.net-core - Identity Server 4 上的关联失败
问题描述
我有一个配置了 OpenIdConnect 到 Azure AD的Identity Server 4 。
当用户单击登录按钮时,IS4 重定向到 Azure AD 并在回调到 IS4 时,它显示此错误:
这就是我向邮递员请求令牌的方式:
请注意,回调 url 是移动应用程序格式。
这是我的配置:
services.AddAuthentication()
.AddCookie(options => new CookieAuthenticationOptions
{
ExpireTimeSpan = TimeSpan.FromHours(12),
SlidingExpiration = false,
Cookie = new CookieBuilder
{
Path = "",
Name = "MyCookie"
}
}).AddOpenIdConnect(options =>
{
options.ClientId = configuration["OpenIdConnect:ClientId"];
options.Authority = configuration["OpenIdConnect:Authority"];
options.SignedOutRedirectUri = configuration["OpenIdConnect:PostLogoutRedirectUri"];
options.CallbackPath = configuration["OpenIdConnect:CallbackPath"];
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.Resource = configuration["OpenIdConnect:Resource"];
options.ClientSecret = configuration["OpenIdConnect:ClientSecret"];
options.SaveTokens = true;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",
RoleClaimType = "role"
};
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
});
这是我的参数:
"OpenIdConnect": {
"ClientId": "xxxxxxxxxx",
"Authority": "https://login.microsoftonline.com/xxxxxxxxxx/",
"PostLogoutRedirectUri": "https://uri-of-my-identity-server.azurewebsites.net",
"CallbackPath": "/signin-oidc",
"ResponseType": "code id_token",
"Resource": "https://graph.microsoft.com/",
"ClientSecret": "my-secret"
},
注意:此错误仅发生在Azure 环境中(不在本地)
注意:在 Xamarin 应用程序上,当 Azure 返回 IS4 同意屏幕时,它会显示以下消息:
解决方案
可能是您的客户端和 Azure 之间的网络存在问题。某个端口尚未打开或负载均衡器介于两者之间。
When decryption fails, state is null, thus resulting in a Correlation failed: state not found error. In our case, decryption failed because different keys were used for encryption/decryption, a pretty common problem when deploying behind a load balancer.
推荐阅读
- python - 根据值拆分 DataFrame
- python - 使用朴素贝叶斯计算测试数据的概率
- excel - Excel VBA:在 Mac 上获取 Yahoo Finance 数据
- visual-studio - 为什么我必须将源 `.asm` 文件的 `Properties > General > Item Type` 设置为 `Microsoft Macro Assembler` ...?
- flutter - 使用 GetX 可观察对象时,哪些 UI 小部件需要包装在 Obx 中?
- docker - 构建派生图像时无法在缓存中找到(本地)图像
- reactjs - 警告:无效的属性名称:`'data-*'`
- apache-spark - 在执行器上访问 SparkSession 会引发错误
- ruby-on-rails - 未捕获的类型错误:无法在 utils.js:50 处读取未定义的属性“模式”在stimulus_reflex.js:328
- git - 使用 Dist::Zilla::Plugin::Gatherdir 添加一个未跟踪的文件