【发布时间】:2018-05-21 11:50:51
【问题描述】:
我在 Github 上提出了一个错误,但想看看是否有人也可以提供帮助。 Bug #1839
问题/重现问题的步骤
我正在尝试使用 openId Connect 对我们的 azure 广告进行身份验证,但在回调方法之后我被重定向到 /Account/AccessDenied
身份验证完成后,Azure 重定向回回调方法。
/// <summary>
/// Post processing of external authentication. Callback from azure.
/// </summary>
[HttpGet]
public async Task<IActionResult> TprUserLoginCallback(string returnUrl)
{
// read external identity from the temporary cookie
var claimsPrincipal = await HttpContext.Authentication.AuthenticateAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme);
if (claimsPrincipal == null)
{
throw new Exception("External authentication error");
}
var claimResult = externalClaimsMapper.Map(claimsPrincipal);
var claims = claimResult.Claims.ToArray();
await HttpContext.Authentication.SignInAsync(claimResult.UserId, claimResult.UserName, claimResult.Provider, claims);
return Redirect(interactionService.IsValidReturnUrl(returnUrl) ? returnUrl : "~/");
}
然后重定向似乎进入了 asp 核心中间件 (v1.1.3),它在日志中添加了一个条目,说明 cookie 被禁止。
2017-12-06 11:01:13,920 [40] 信息 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware.Log - AuthenticationScheme:idsrv.external 被禁止,然后页面重定向到 /Account/AccessDenied。
2017-12-06 11:01:13,921 [40] 信息 Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectMiddleware.Log - AuthenticationScheme:OpenIdConnect 被禁止。
启动 - cookie auth 和 openid 连接 auth
app.UseIdentityServer();
var appSettings = container.GetInstance<AppSettings>();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,
AutomaticAuthenticate = false,
AutomaticChallenge = false,
ExpireTimeSpan = TimeSpan.FromMinutes(appSettings.DefaultTokenLifetimeInMinutes)
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
ClientId = appSettings.AzureClientId,
Authority = appSettings.AzureAuthority,
PostLogoutRedirectUri = appSettings.AzurePostLogoutRedirectUri,
DisplayName = "TPR Login",
SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,
ResponseType = OpenIdConnectResponseType.IdToken,
SaveTokens = true,
RequireHttpsMetadata = false // F5's HTTPS handling so traffic will be HTTP
});
app.UseStaticFiles();
app.UseCors("default");
app.UseMvc(ConfigureRoutes.Configure);
在您被重定向后,如果您手动导航到该 url,用户已经登录并且可以访问应用程序
日志文件的相关部分
2017-12-06 11:01:13,899 [40] 信息 Microsoft.AspNetCore.Hosting.Internal.WebHost.Log - 请求开始 HTTP/1.1 GET http://localhost:44362/ 2017-12-06 11:01:13,900 [40] 调试 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Log - 使用目的对密钥 {144dcece-5570-4965-a74c-0ec3aed546e8} 执行取消保护操作 ('C:\code\tfs03\Single Sign On\Login\ReleaseSSO-Dev\WebUI\Login.IdentityServer', 'Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware', 'idsrv'、'v2')。 2017-12-06 11:01:13,902 [40] 信息 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware.Log - HttpContext.User 通过来自 authenticationScheme 的 AutomaticAuthentication 合并:idsrv。 2017-12-06 11:01:13,904 [40] 信息 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware.Log - AuthenticationScheme:idsrv 已成功通过身份验证。 2017-12-06 11:01:13,905 [40] 调试 IdentityServer4.Hosting.EndpointRouter.Log - 未找到端点条目 对于请求路径:/ 2017-12-06 11:01:13,906 [40] DEBUG Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Log - 的 请求路径/与支持的文件类型不匹配 2017-12-06 11:01:13,909 [40] 调试 Microsoft.AspNetCore.Routing.RouteBase.Log - 请求成功匹配名称为“default”的路由,并且 模板'{controller=Login}/{action=Login}'。 2017-12-06 11:01:13,910 [40] 调试 Microsoft.AspNetCore.Mvc.Internal.ActionSelector.Log - 操作'Login.IdentityServer.Controllers.LoginController.Login (Login.IdentityServer)' 带有 id 'cba23692-b89e-4fe7-bf59-ccc14c18352a' 与约束不匹配 'Microsoft.AspNetCore.Mvc.Internal.HttpMethodActionConstraint' 2017-12-06 11:01:13,911 [40] 调试 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Log - 执行动作 Login.IdentityServer.Controllers.LoginController.Login (Login.IdentityServer) 2017-12-06 11:01:13,913 [40] 信息 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Log - 执行动作方法 Login.IdentityServer.Controllers.LoginController.Login (Login.IdentityServer) 带参数 () - ModelState 是有效的 2017-12-06 11:01:13,914 [40] 调试 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Log - 执行的动作方法 Login.IdentityServer.Controllers.LoginController.Login (Login.IdentityServer),返回结果 Microsoft.AspNetCore.Mvc.ChallengeResult。 2017-12-06 11:01:13,915 [40] 信息 Microsoft.AspNetCore.Mvc.ChallengeResult.Log - 正在执行 ChallengeResult 与身份验证方案 (OpenIdConnect)。 2017-12-06 11:01:13,917 [40] 调试 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Log - 使用目的对密钥 {144dcece-5570-4965-a74c-0ec3aed546e8} 执行取消保护操作 ('C:\code\tfs03\Single Sign On\Login\ReleaseSSO-Dev\WebUI\Login.IdentityServer', 'Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware', 'idsrv.external'、'v2')。 2017-12-06 11:01:13,918 [40] 信息 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware.Log - AuthenticationScheme:idsrv.external 已成功通过身份验证。 2017-12-06 11:01:13,920 [40] 信息 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware.Log - AuthenticationScheme:idsrv.external 被禁止。 2017-12-06 11:01:13,921 [40] 信息 Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectMiddleware.Log - AuthenticationScheme:OpenIdConnect 被禁止。 2017-12-06 11:01:13,922 [40] 信息 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Log - 执行的动作 Login.IdentityServer.Controllers.LoginController.Login (Login.IdentityServer) 在 10.0229 毫秒 2017-12-06 11:01:13,924 [40] 调试 Microsoft.AspNetCore.Server.Kestrel.Log - 连接 ID “0HL9SILL2SM7P”完成保活响应。 2017-12-06 11:01:13,926 [40] 信息 Microsoft.AspNetCore.Hosting.Internal.WebHost.Log - 请求 在 26.936 毫秒内完成 302 2017-12-06 11:01:13,930 [24] 信息 Microsoft.AspNetCore.Hosting.Internal.WebHost.Log - 请求开始 HTTP/1.1 获取 http://localhost:44362/Account/AccessDenied?ReturnUrl=%2Flogin%2Ftpruserlogincallback 2017-12-06 11:01:13,932 [24] 调试 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Log - 使用目的对密钥 {144dcece-5570-4965-a74c-0ec3aed546e8} 执行取消保护操作 ('C:\code\tfs03\Single Sign On\Login\ReleaseSSO-Dev\WebUI\Login.IdentityServer', 'Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware', 'idsrv'、'v2')。 2017-12-06 11:01:13,934 [24] 信息 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware.Log - HttpContext.User 通过来自 authenticationScheme 的 AutomaticAuthentication 合并:idsrv。 2017-12-06 11:01:13,935 [24] 信息 Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware.Log - AuthenticationScheme:idsrv 已成功通过身份验证。 2017-12-06 11:01:13,936 [24] 调试 IdentityServer4.Hosting.EndpointRouter.Log - 未找到端点条目 对于请求路径:/Account/AccessDenied 2017-12-06 11:01:13,938 [24] 调试 Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Log - 的 请求路径 /Account/AccessDenied 与支持的文件不匹配 类型 2017-12-06 11:01:13,940 [24] 调试 Microsoft.AspNetCore.Routing.RouteBase.Log - 请求成功 匹配名称为“默认”和模板的路由 '{controller=Login}/{action=Login}'。 2017-12-06 11:01:13,941 [24] 调试 Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler.Log - 否 动作匹配当前请求 2017-12-06 11:01:13,943 [24] DEBUG Microsoft.AspNetCore.Builder.RouterMiddleware.Log - 请求没有 匹配任何路线。 2017-12-06 11:01:13,945 [24] 调试 Microsoft.AspNetCore.Server.Kestrel.Log - 连接 ID “0HL9SILL2SM7P”完成保活响应。 2017-12-06 11:01:13,946 [24] 信息 Microsoft.AspNetCore.Hosting.Internal.WebHost.Log - 请求 在 15.7755 毫秒内完成 404
【问题讨论】:
标签: c# asp.net-mvc azure openid-connect identityserver4