3
votes

I'm using Django rest-auth for authentication and account creation with Django rest framework. Currently, I have six providers set up and I'd like to start connecting them.

It's not clear from the documentation (either rest-auth or all-auth) what I have to do to connect the accounts.

For example, if I try to connect a Google account to a LinkedIn one (same email address), even if I make a POST request to /rest-auth/linkedin/connect/ with the correct access token for the Google provider, I get a 400 response saying: "non-field-errors": [ "Incorrect value" ].

I'm using JWTs for authentication, and providing the correct token in the Authorization header.

views.py

class GoogleConnect(SocialConnectView):
    adapter_class = GoogleOAuth2Adapter

class LinkedInConnect(SocialConnectView):
    adapter_class = LinkedInOAuth2Adapter
1
I guess this package is close to useless then. I may as well have implemented it myself.HPJM

1 Answers

0
votes

I've written a tutorial that should cover your question. This should be the part you are looking for.

In short: You have to write your own ConnectView which inherits from the rest_auth view like this:

class GoogleCallbackConnect(SocialConnectView):
    """
    Connects the provider's user account to the currently logged in user.
    """
    adapter_class = GoogleOAuth2Adapter
    client_class = OAuth2Client

    @property
    def callback_url(self):
        url = self.adapter_class(self.request).get_callback_url(
            self.request,
            None,
        )
        return url