question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is redirectUri working as intended?

See original GitHub issue

I am loading the component as follows:

      <GoogleLogin
        clientId="<client_id"
        buttonText={text}
        scope={scope}
        onSuccess={this.responseGoogle}
        onFailure={this.responseGoogle}
        cookiePolicy={'single_host_origin'}
        disabled={disabled}
        responseType={'code'}
        accessType={'offline'}
        uxMode={'redirect'}
        redirectUri={'https://localhost:5000/google_oauth_redirect'}
      />

I have tried a host of different redirectUri’s in their but both 1) none of them seem to be passed to the popup* and 2) I keep getting an error via the python server that is using the returned code that the redirect_uri is a mismatch.

  • Why is this a popup and not a redirect? Am I doing something wrong there as well?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
jedashfordcommented, Jun 24, 2020

We figured it out. On the server, you must set the redirect_uri=“postmessage” . This does break codes from mobile clients, so we needed to make it dynamic by client, but for this library, and our params, this fixes it and we’re able successfully validate codes.

OAuth2.Client.new([
      strategy: __MODULE__,
      client_id: ...,
      client_secret: ...,
      redirect_uri: "postmessage",
      site: "https://accounts.google.com",
      authorize_url: "/o/oauth2/auth",
      token_url: "/o/oauth2/token"
    ])

More info here: https://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch

1reaction
vesspercommented, Apr 24, 2020

I am having the same problem and will need some help. Since ‘react-google-login’ seems to be quite mature this probably is a reconfiguration. I also get redirect_uri_mismatch back from my backend.

I use the component like so:

<GoogleLogin
     clientId="XXXXXX.apps.googleusercontent.com"
     buttonText="Continue with Google"
     responseType={"code"}
     redirectUri={'http://localhost:8000/'}
     onSuccess={handleGoogleLogIn}
     onFailure={handleGoogleError}
     cookiePolicy={'single_host_origin'}
 />

For my local dev I use redirectUri={‘http://localhost:8000/’}, both this and the correct origin are added to the https://console.cloud.google.com/apis/credentials console.

I do not see the redirect_uri argument in the outgoing request. The request is:

https://accounts.google.com/o/oauth2/iframerpc?action=issueToken&response_type=token%20id_token&login_hint=AXXXXXXXX&client_id=XXX.apps.googleusercontent.com&origin=http%3A%2F%2Flocalhost%3A8000&scope=openid%20profile%20email&ss_domain=http%3A%2F%2Flocalhost%3A8000

The code is received OK. The corresponding request from my backend is:

send: b'POST /o/oauth2/token HTTP/1.1\r\nHost: accounts.google.com\r\nUser-Agent: python-requests/2.22.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 294\r\n\r\n'
send: b'grant_type=authorization_code&code=XXXX&client_id=XXXX.apps.googleusercontent.com&client_secret=XXXX&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F'
reply: 'HTTP/1.1 400 Bad Request\r\n'
header: Content-Type: application/json; charset=utf-8
header: Vary: Origin
header: Vary: X-Origin
header: Vary: Referer
header: Content-Encoding: gzip
header: Date: Wed, 22 Jan 2020 10:06:01 GMT
header: Server: ESF
header: Cache-Control: private
header: X-XSS-Protection: 0
header: X-Frame-Options: SAMEORIGIN
header: X-Content-Type-Options: nosniff
header: Alt-Svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000
header: Transfer-Encoding: chunked
Authentication process canceled; ; {'error': 'redirect_uri_mismatch', 'error_description': 'Bad Request'}
WARNING Bad Request: /api/v1/login/social/knox_user/google-oauth2/
WARNING "POST /api/v1/login/social/knox_user/google-oauth2/ HTTP/1.1" 400 0

Version 5.1.10

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to fix redirect uri not valid? - Microsoft Q&A
I've managed to log in by signing out of chrome and using an incognito tab. It still doesnt work when im signed in...
Read more >
Redirect uri not working - Stack Overflow
I'm trying to implement the oauth google authentication in symfony2 with hwi oauth bundle. I added the button and the popup open and...
Read more >
What is the purpose of OAuth 2.0 redirect_uri checking?
Authentication is about intention, tricking a user into allowing access to an unintended resource is a vulnerability.
Read more >
Redirect Users - Auth0
To learn more about how the redirect_uri works, see OAuth 2.0 ... URL to redirect the user back to their intended page after...
Read more >
Invalid redirect uri for "Valid Redirect URIs with https://*"
What is the full URL of that 'keycloak sso page'. There is requested redirect url parameter and that one can be really http,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found