首页 > 解决方案 > 启用 Google 身份验证:请求中的重定向 URI 与授权给 OAuth 客户端的不匹配

问题描述

我想在我的 Web 应用程序 (ASP.NET Core 3.1) 中启用 Google 身份验证。我收到了这个错误:

请求中的重定向 URI https://localhost:44345/signin-google与授权给 OAuth 客户端的重定向 URI 不匹配。要更新授权的重定向 URI,请访问: https ://console.developers.google.com/apis/credentials/oauthclient/ ...

我该如何解决?

我在我的 console.developers.google.com 中设置了重定向 Uri,如下所示:

授权的 JavaScript 来源

URI:

https://localhost:44345

授权的重定向 URI

URI:

https://localhost:44345/Account/GoogleResponse

授权的重定向 URI

帐户控制器:

    [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

标签: c#asp.netauthenticationasp.net-coregoogle-authentication

解决方案


推荐阅读