Search code examples
google-oauth

The redirect URI in the request, http://localhost:8080/, does not match the ones authorized for the OAuth client


I'm trying to organize access to Google Ads API.

I'm stuck at step 3 here: https://developers.google.com/google-ads/api/docs/client-libs/python/oauth-web#step_3_-_generating_a_refresh_token

Namely, getting a refresh token.

I do this:

$ ./authenticate_in_web_application.py --client_secrets_path=/path/to/secrets.json

secrets.json

{
    "web": {
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "client_id": "some_client_id",
        "client_secret": "i_m_so_secret",
        "javascript_origins": [
            "https://avtomotokniga.ru"
        ],
        "project_id": "smpt-auth",
        "redirect_uris": [
            "https://avtomotokniga.ru/"
        ],
        "token_uri": "https://oauth2.googleapis.com/token"
    }
}

When the script runs, it provides me with a hyperlink. I follow the link and find this:

Error 400: redirect_uri_mismatch
The redirect URI in the request, http://localhost:8080/, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/secret-uvml458ip15qmarbruq83bkmfbu3vilf.apps.googleusercontent.com?project=secret

Problem

Where localhost:8080 is taken from?

I double-checked secrets.json and the credentials page (https://console.developers.google.com/apis/credentials).

The Redirect URI is definitely there:

enter image description here

And it is saved. I opened and closed the page several times. And the json file is downloaded, that is the redirect URI is definitely taken into account.

How can I localize the problem?


Solution

  • If you don't explicitly specify returnURL, Google provides default as "/google-signin".

    In .NET, startup.auth.cs file, add the URL as

    //google OAuth 2.0 Client IDs 
    app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
    {
        ClientId = "456545-r6k8kf3gffghpoh13212s1fnkkfe.apps.googleusercontent.com",
        ClientSecret = "VWuu45654655IeNUDEw32",
        CallbackPath = new PathString("/CONTROLLER/ExternalLoginCallbackFUNCTION")
    });