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:
Authorized redirect URIs
URIs:
https://localhost:44345/Account/GoogleResponse
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
}
}

