c# - 启用 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:
授权的重定向 URI
URI:
https://localhost:44345/Account/GoogleResponse
启动类 > ConfigureServices(IServiceCollection services) 方法:
services.AddAuthentication().AddGoogle(opts => { opts.ClientId = "xxx.apps.googleusercontent.com"; opts.ClientSecret = "yyy"; });
帐户控制器:
[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
}
}
解决方案
推荐阅读
- c++ - 如何在 GDB 调试器命令行中调用 std::function 句柄
- c# - 尝试管理 Nuget 包时找不到 MSBuildProjectExtensionsPath MSBuild 属性
- javascript - Document.querySelector() 返回未定义的值
- python -
返回 NULL 而不设置错误 - mysql - 在 WooCommerce 中添加订单时出现 Wordpress MySQL 错误
- css - 在每个 .Rd 文件中自动调用宏或插入模板
- c++ - 直接使用 postgres JSONB
- kotlin - 如何将可为空的流转换为 LiveData
- embedding - 使用 BERT 嵌入语料库(以及保存词汇)而不使用预训练的 BERT
- javascript - 角度材料中的动画不起作用。问题不在于 NoopAnimationsModule 或 app.module.ts 中的材质或导出版本