Enabling Google Authentication: The redirect URI in the request, does not match the ones authorized for the OAuth client

Viewed 1100

I want to enable Google Authentication in my web application (ASP.NET Core 3.1). I got this error:

The redirect URI in the request, https://localhost:44345/signin-google, 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/...

How can I solve it?

I have set the redirect Uri in my console.developers.google.com like this:

Authorized JavaScript origins

URIs:

https://localhost:44345

Authorized redirect URIs

URIs:

https://localhost:44345/Account/GoogleResponse

Authorized redirect URIs

  • Startup class > ConfigureServices(IServiceCollection services) method:

    services.AddAuthentication().AddGoogle(opts =>
        {
            opts.ClientId = "xxx.apps.googleusercontent.com";
            opts.ClientSecret = "yyy";
        });
    

AccountController:

    [Authorize]
    public class AccountController : BaseController
    {


       [AllowAnonymous]
       public IActionResult GoogleLogin(string returnUrl)
       {
           string redirectUrl = Url.Action("GoogleResponse", "Account", new { ReturnUrl = returnUrl });
           var properties = signInManager
            .ConfigureExternalAuthenticationProperties("Google", redirectUrl);
           return new ChallengeResult("Google", properties);
       }

       [AllowAnonymous]
       public async Task<IActionResult> GoogleResponse(string returnUrl = "/")
       {
           // some codes
       }

   }

redirect_uri_mismatch

0 Answers
Related