Skip to content
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 OAuth Redirect Uri Missmatch error, but urls seem to be configured correctly #458

Closed
adrenaline681 opened this issue Nov 30, 2022 · 3 comments

Comments

@adrenaline681
Copy link
Contributor

  1. On my frontend (ReactJs) I'm login using Google and getting the "code" using the Auth Code Flow which looks something like this:
{
    "code": "4/0AfteXvtM-2XB5q-cTe-l-oYTkkRg-3QZf8V44cEvrRvCpPR9gSXhn76dF-oU2SPxDNvSpw",
    "scope": "email profile openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email",
    "authuser": "0",
    "prompt": "consent"
}
  1. Then I'm sending this in the body of a POST request to my DRF API which lands on this view:
class GoogleLogin(SocialLoginView):
    adapter_class = GoogleOAuth2Adapter
    client_class = OAuth2Client
    callback_url = 'http://localhost:8000/accounts/google/login/callback/'
  1. In my Google Console I have the same callback URL setup under OAuth 2.0 Client IDs:
    image

  2. But I keep getting the same error:

Error retrieving access token: {
    "error": "redirect_uri_mismatch",
    "error_description": "Bad Request"
}
@adrenaline681 adrenaline681 changed the title Google OAuth Redirect URI Missmatch error, but urls seem to be configured correctly Google OAuth Redirect Uri Missmatch error, but urls seem to be configured correctly Nov 30, 2022
@Korben11
Copy link

Having the same issue, did you find the cause?

@adrenaline681
Copy link
Contributor Author

No, I ended up using Implicit flow instead since I only needed to get user information on login.

class GoogleLoginView(SocialLoginView):
    adapter_class = GoogleOAuth2Adapter

@adrenaline681
Copy link
Contributor Author

I'm leaving the solution that helped me. I've lost so many hours maybe this can help someone else save some time.

The trick was to set the callback_url to postmessage

class GoogleLoginView(SocialLoginView):
    adapter_class = GoogleOAuth2Adapter
    callback_url = 'postmessage'  
    client_class = OAuth2Client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants