New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google Social Authentication with dj-rest-auth #220
Comments
Did you work around: |
I think that downgrading to django-rest-framework v3.10.3 solved the issue for me. |
#147 (comment) this would also help you out I think. Thanks for the quick response! |
How did you decode the URL? I'm hitting this error and it looks like the |
You can use urllib for the decoding.
|
Thanks for creating this issue and documenting a solution that works for Oauth + Google. I'm going to close this ticket, but feel free to post any updates here. |
This endpoint expects the code, token sent in JSON right? EDIT: Duh, dumb me. I had a global header always being set on my front end which caused it to add a conte-type:application/json to the request, when it should've been x-www-urlencoded. The response from the serializer made me think it expected json though, hehe. |
How to get access token and code? |
generally u get the access token from the front end and if u want to test the apis u can use |
Thank you so much |
I've spent a a lot of time on implementing Google oAuth with dj-rest-auth which should be easier, and I'll post my solution here, hoping it'll help somebody else.
views.py
urls.py
path(r'auth/google', GoogleLogin.as_view(), name='google_login')
settings.py
The
callback_url
andclient_class
are only required if you're sending onlycode
i.e.authorization_code
to Google oAuth URL.The problem I had was that after making the request to
https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=<callback-url>&prompt=consent&response_type=code&client_id=<your_client_id>&scope=openid%20email&access_type=offline
(change the callback_url and client_id with the ones from your app), as a response I got back the code. When sending the code to the /auth/google URL, i got this errorError retrieving access token: b'{\n “error”: “redirect_uri_mismatch”,\n “error_description”: “Bad Request”\n}'
. This was because the code is URL safe, which means you'll need to first decode it and then send it to your API endpoint.The text was updated successfully, but these errors were encountered: