关联失败。在 OIDC 身份验证期间 Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler
Correlation failed. at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler during OIDC authentication
我用以下组合打这个:
- 浏览器隐身模式(Chrome)
- 应用程序在 Azure 应用程序网关后面(如果不是,则无法重现)。基于 Cookie 的亲和力已关闭(默认);如果打开,似乎会更频繁地进行重现。
代码是相当普通的普通 OIDC authN + cookies。
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddAzureAd(options => {
Configuration.Bind("AzureAd", options);
})
.AddCookie(p => p.SlidingExpiration = true);
我正在按照建议将 X-Forwarded-Proto header 转发到 auth 中间件,以便 redirect_uri 使用正确的协议方案。
代码处理
我试图处理 OnRemoteFailure() 事件,并重定向到“/Home/AuthRedirect”,这是一个等待 20 秒的匿名页面,然后重定向到“/”(主页)。它似乎有时有效,但并非总是有效。我没主意了。
解决方法
- 用户可以再次进入主页并按 F5 直至成功。似乎每个 F5 都让他们向前迈进了一步,一旦 OpenID cookie 被填充,其他一切(在 openid 完成后我有更多的授权,通过 adal.js 供 AJAX 使用)。
- 绕过应用程序网关并使用直接服务结构集群 DNS 名称(不可接受,因为它是 http)。
详情
System.Exception: Correlation failed.
at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()
我有同样的问题,如果你的环境是网络农场,你应该使用 DataProtection 来共享密钥。
我遇到了同样的问题。我正在为授权定义多个外部端点。
在我的例子中,我定义了多个客户端正在使用的回调路径。
一旦我定义了唯一的回调路径,问题就解决了:
示例:
options.Authority = …..";
.
.
options.CallbackPath = "/signin-idsrv2"; // I already had /sign-in-idsrv
同样,确保 SignedOutCallbackPaths
是唯一的。
希望对你有用。
我有同样的问题,但我的问题是由于我对授权工作流程的理解是错误的。
有两个回调 URL 很重要,我认为它们的作用相同。我错了。
这是在Startup.cs
中定义的
.AddOpenIdConnect("Auth0", options =>
{
options.CallbackPath = new PathString("/signin-auth0");
它告诉应用程序中的授权中间件,一旦身份验证提供程序在身份验证成功后返回,它应该在哪个 URL 上监听。
然后中间件本身会将应用程序重定向到您的登录操作中定义的回调 URL(示例代码如下)。
在那之后(奋斗了两天),一切都开始了。
public class AccountController : Controller
{
[HttpGet]
public async Task Login()
{
await HttpContext.ChallengeAsync("Auth0", new AuthenticationProperties() { RedirectUri = "/my-callback-page" });
}
}
我在 Chrome 中遇到了类似的关联错误,但在 Safari 中却没有...事实证明,当使用 SameSite.None 时,您必须 运行 您的自定义站点(甚至本地主机)使用https。这解决了我所有的相关问题。
我猜你的例子不是这种情况,但就在今天更改为冬季时间后,我遇到了同样的错误消息问题 - 我的时钟由于某种原因没有自动同步,系统时间仍然是一小时提前 - 与远程时间服务器同步后,一切都重新开始工作。我希望有人觉得这有帮助。
我用以下组合打这个:
- 浏览器隐身模式(Chrome)
- 应用程序在 Azure 应用程序网关后面(如果不是,则无法重现)。基于 Cookie 的亲和力已关闭(默认);如果打开,似乎会更频繁地进行重现。
代码是相当普通的普通 OIDC authN + cookies。
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddAzureAd(options => {
Configuration.Bind("AzureAd", options);
})
.AddCookie(p => p.SlidingExpiration = true);
我正在按照建议将 X-Forwarded-Proto header 转发到 auth 中间件,以便 redirect_uri 使用正确的协议方案。
代码处理
我试图处理 OnRemoteFailure() 事件,并重定向到“/Home/AuthRedirect”,这是一个等待 20 秒的匿名页面,然后重定向到“/”(主页)。它似乎有时有效,但并非总是有效。我没主意了。
解决方法
- 用户可以再次进入主页并按 F5 直至成功。似乎每个 F5 都让他们向前迈进了一步,一旦 OpenID cookie 被填充,其他一切(在 openid 完成后我有更多的授权,通过 adal.js 供 AJAX 使用)。
- 绕过应用程序网关并使用直接服务结构集群 DNS 名称(不可接受,因为它是 http)。
详情
System.Exception: Correlation failed. at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()
我有同样的问题,如果你的环境是网络农场,你应该使用 DataProtection 来共享密钥。
我遇到了同样的问题。我正在为授权定义多个外部端点。 在我的例子中,我定义了多个客户端正在使用的回调路径。 一旦我定义了唯一的回调路径,问题就解决了: 示例:
options.Authority = …..";
.
.
options.CallbackPath = "/signin-idsrv2"; // I already had /sign-in-idsrv
同样,确保 SignedOutCallbackPaths
是唯一的。
希望对你有用。
我有同样的问题,但我的问题是由于我对授权工作流程的理解是错误的。 有两个回调 URL 很重要,我认为它们的作用相同。我错了。
这是在Startup.cs
中定义的.AddOpenIdConnect("Auth0", options =>
{
options.CallbackPath = new PathString("/signin-auth0");
它告诉应用程序中的授权中间件,一旦身份验证提供程序在身份验证成功后返回,它应该在哪个 URL 上监听。 然后中间件本身会将应用程序重定向到您的登录操作中定义的回调 URL(示例代码如下)。
在那之后(奋斗了两天),一切都开始了。
public class AccountController : Controller
{
[HttpGet]
public async Task Login()
{
await HttpContext.ChallengeAsync("Auth0", new AuthenticationProperties() { RedirectUri = "/my-callback-page" });
}
}
我在 Chrome 中遇到了类似的关联错误,但在 Safari 中却没有...事实证明,当使用 SameSite.None 时,您必须 运行 您的自定义站点(甚至本地主机)使用https。这解决了我所有的相关问题。
我猜你的例子不是这种情况,但就在今天更改为冬季时间后,我遇到了同样的错误消息问题 - 我的时钟由于某种原因没有自动同步,系统时间仍然是一小时提前 - 与远程时间服务器同步后,一切都重新开始工作。我希望有人觉得这有帮助。