Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect_uri_mismatch the redirect URI in the request does not match the ones authorized for the OAuth client

I have following client secret

{
  "web": {
    "client_id": "testid",
    "project_id": "testproj",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://www.googleapis.com/oauth2/v3/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "test-sec",
    "redirect_uris": [
      "https://localhost:8080/oauth2callback"
    ]
  }
}

and I am getting

"Error: redirect_uri_mismatch The redirect URI in the request, http://127.0.0.1:8414/authorize/, does not match the ones authorized for the OAuth client.

To update the authorized redirect URIs, visit:". Could you please suggest, how to fix it.

I am using C#. I have created credentials with this -

GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, scopes,
                                             "user",
                                              CancellationToken.None, 
                                              new FileDataStore(Directory.GetCurrentDirectory() + "\\AccessToken\\" , 
                                             true)).Result; 

But for first time , it popped up with login and once I logged in , it has created Google.Apis.Auth.OAuth2.Responses.TokenResponse-user file in the folder. Is there a way to bypass first time login ?

Thanks.

like image 775
Anindita Ghatak Avatar asked Dec 17 '22 19:12

Anindita Ghatak


1 Answers

When you are creating your credentials in https://console.developers.google.com:

Credentials

After cliking on Create credentials by choosing OAuth client ID:

Create credentials

Choose Other as Aplication type:

Create OAuth client ID.

You should have this format of credentials:

{
  "installed": {
    "client_id": "...",
    "project_id": "...",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "...",
    "redirect_uris": [
      "urn:ietf:wg:oauth:2.0:oob",
      "http://localhost"
    ]
  }
}

Now your OAuth2 link should works whatever your port in redirection_uri paramater as http://localhost:8414 for example (with 8414 as random port). And you are no more this error:

Error: redirect_uri_mismatch The redirect URI in the request, http://localhost:8414/authorize/, does not match the ones authorized for the OAuth client.

like image 95
glegoux Avatar answered Dec 26 '22 23:12

glegoux