I want to add details in the JACKSON MOURA code snippet with an explanation.
In settings.py, you have to do this. I didn't find any good documentation. But it works for social authentication. now you don't need to set up the social auth apps by using the admin panel anymore. I showed samples of Google, Facebook, and LinkedIn. It will work with other social apps as well.
SOCIALACCOUNT_PROVIDERS = {
"google": {
"APP": {
"client_id": "<client_id>",
"secret": "<secret>",
},
},
'facebook': {
"APP": {
"client_id": "<client_id>",
"secret": "<secret>",
},
},
"linkedin": {
"APP": {
"client_id": "<client_id>",
"secret": "<secret>",
}
}
}
Now in view.py, you have to create serializer classes. all will be the same. I am showing for Google, LinkedIn, and Facebook.
class FacebookLogin(SocialLoginView):
adapter_class = FacebookOAuth2Adapter
client_class = OAuth2Client
serializer_class = SocialLoginSerializer
def get_serializer(self, *args, **kwargs):
serializer_class = self.get_serializer_class()
kwargs['context'] = self.get_serializer_context()
return serializer_class(*args, **kwargs)
class GoogleLogin(SocialLoginView):
adapter_class = GoogleOAuth2Adapter
client_class = OAuth2Client
serializer_class = SocialLoginSerializer
def get_serializer(self, *args, **kwargs):
serializer_class = self.get_serializer_class()
kwargs['context'] = self.get_serializer_context()
return serializer_class(*args, **kwargs)
class LinkedInLogin(SocialLoginView):
adapter_class = LinkedInOAuthAdapter
client_class = OAuthClient
serializer_class = SocialLoginSerializer
def get_serializer(self, *args, **kwargs):
serializer_class = self.get_serializer_class()
kwargs['context'] = self.get_serializer_context()
return serializer_class(*args, **kwargs)
Now, the backend is ready for getting post data from the frontend and will show perfect error like below. It will work with all other social apps.