identityserver4 - Identityserver4 使用两个相同的外部提供者,第二个外部提供者登录总是失败
问题描述
我使用两个具有不同 clientid 的不和谐提供程序进行登录。以下代码:
services.AddAuthentication()
.AddDiscord("ADiscord", u =>
{
u.ClientId = "74627xxx8536";
u.ClientSecret = "B-FLxxxxjp3JOKwr27";
u.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
u.Scope.Add("guilds.join");
u.SaveTokens = true;
u.CorrelationCookie.SameSite = SameSiteMode.Unspecified;
u.CorrelationCookie.IsEssential = true;
})
.AddDiscord("BDiscord", u =>
{
u.ClientId = "71475xxx1925";
u.ClientSecret = "45-xxxA4okXx1I";
u.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
u.Scope.Add("guilds.join");
u.SaveTokens = true;
u.CorrelationCookie.SameSite = SameSiteMode.Unspecified;
u.CorrelationCookie.IsEssential = true;
});
当我使用方案“ADiscord”登录时,一切正常。但是使用方案“BDiscord”它会抛出错误“来自 RemoteAuthentication 的错误:oauth 状态丢失或无效”。更奇怪的是,如果更改顺序让“BDiscord”在顶部然后使用方案“BDiscord”登录一切正常,“ADiscord”会抛出错误。
Disord 提供程序代码位于https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/tree/dev/src/AspNet.Security.OAuth.Discord
解决方案
您需要设置CallbackPath,将其设置为 sth like/signin-discord
并/signin-discord
使用 IdSvr4 注册。此端点用于在重定向到应用程序端点之前完成 OAuth 握手。
推荐阅读
- java - 在 JPQL Native Query 中将查询作为查询参数传递
- zuul-ci - 作业配置:将元素添加到现有文件列表
- ios - 如何在动态框架中隐藏静态库
- php - 如何使用 AllowOverride 指令来允许 .htaccess 文件覆盖 php_value (Apache2)
- google-sheets - 已发布工作表中具有锁定列的附加行
- c# - 发布多个机器人的最佳实践
- android - 在 build.gradle 中定义一个变量并在网络 XML 文件中使用该值
- python - 拆分包含两个值的列
- django - Django 模板系统
- python - Selenium / More-Element 点击总是不可能的?