Method GET not allowed -- Social Login, OAauth2 with code callback
Hey guys, I'm trying to setup social login through OAuth2 with Github. I've followed along with what you guys have said for google login here: https://github.com/Tivix/django-rest-auth/issues/316#issuecomment-310358200
But I'm getting Method GET not allowed. So what I have is this:
class GithubLogin(SocialLoginView):
"""
View to login by github
"""
adapter_class = GitHubOAuth2Adapter
client_class = OAuth2Client
callback_url = 'http://localhost:8000/accounts/github/login/callback/'
url(r'^api/auth/github/$', user_views.GithubLogin.as_view()),
And I'm setting my redirect_uri for Github to localhost:8000/api/auth/github/. This is the right way to setup the OAuth2 setup correct?
It's sending a GET back with a localhost:8000/api/auth/github/code=CODE&state=PREVIOUS_STATE param. I would expect the GithubLogin class to handle the GET and take in the CODE that we received and then POST to get the access token.
Is my thinking correct?
Did you ever figure out a way to do this?
Yes. It's a bug in the django-allauth code, so I rewrote that specific set of authorizations from allauth...
Wish I could tell you there was an easy fix but you basically need to rewrite the githubLogin view.
@lightninglu10 I just tried out the allauth example application and was able to successfully authenticate with github, if the issue was with allauth, i would not expect the example app to work. Are you sure the bug was/is in the django-allauth package, or could it have been in the django-rest-auth package? or has the issue been fixed maybe?
Thanks in advance :)
This is still a bug.
It can easily be monkey patched like so:
class TwitchLogin(SocialLoginView):
adapter_class = TwitchOAuth2Adapter
callback_url = 'http://localhost:8080/accounts/twitch/'
client_class = OAuth2Client
def get(self, request, *args, **kwargs):
request.data['code'] = request.query_params['code']
return self.post(request, *args, **kwargs)
Still, the view should handle a GET request properly.