【发布时间】:2017-04-05 13:51:14
【问题描述】:
我看到 IdentityServer3 和外部提供程序的奇怪行为。我希望有人能够指出我遗漏的一些明显的东西。
总结
第一个外部登录请求设置浏览器等待请求返回,并导致以下错误仅通过日志记录可见。如果我在浏览器中取消请求并立即再次单击该按钮,它将按预期工作,浏览器被发送到外部登录屏幕。
配置
我已经根据一些参考资料和文档以及我可以确定的配置了 IDSrv3,以利用 Azure Active Directory。
var wsFedOptions = new WsFederationPluginOptions(options);
wsFedOptions.Factory.Register(new Registration<IEnumerable<RelyingParty>>(RelyingParties.Get()));
wsFedOptions.Factory.RelyingPartyService = new Registration<IRelyingPartyService>(typeof(InMemoryRelyingPartyService));
app.UseWsFederationPlugin(wsFedOptions);
var aad = new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "AzureAd",
Caption = "Azure AD",
SignInAsAuthenticationType = signInAsType,
PostLogoutRedirectUri = Settings.LogoutRedirect,
Authority = Settings.AADAuthority,
ClientId = Settings.AADClientId,
RedirectUri = Settings.AADRedirectUrl
};
app.UseOpenIdConnectAuthentication(aad);
在登录视图中,如预期的那样,我看到了上面标题 (Azure AD) 的外部登录按钮。第一次单击此按钮时,浏览器只是等待主机...
在日志中我发现了以下错误。
iisexpress.exe Information: 0 : 2017-04-05 08:28:09.708 -05:00 [Information] External login requested for provider: "AzureAd"
iisexpress.exe Information: 0 : 2017-04-05 08:28:09.714 -05:00 [Information] Triggering challenge for external identity provider
LibLog Information: 0 : [2017-04-05T13:28:09.7176576Z] Level=Info, Kind=End, Category='System.Web.Http.Action', Id=800000ad-0002-fb00-b63f-84710c7967bb, Message='Action returned 'System.Web.Http.Results.UnauthorizedResult'', Operation=ReflectedHttpActionDescriptor.ExecuteAsync
LibLog Information: 0 : [2017-04-05T13:28:09.7206611Z] Level=Info, Kind=End, Category='System.Web.Http.Action', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=ApiControllerActionInvoker.InvokeActionAsync, Status=401 (Unauthorized)
LibLog Information: 0 : [2017-04-05T13:28:09.7216630Z] Level=Info, Kind=Begin, Category='System.Web.Http.Filters', Id=800000ad-0002-fb00-b63f-84710c7967bb, Message='Action filter for 'LoginExternal(String signin, String provider)'', Operation=NoCacheAttribute.OnActionExecutedAsync, Status=401 (Unauthorized)
LibLog Information: 0 : [2017-04-05T13:28:09.7226640Z] Level=Info, Kind=End, Category='System.Web.Http.Filters', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=NoCacheAttribute.OnActionExecutedAsync, Status=401 (Unauthorized)
LibLog Information: 0 : [2017-04-05T13:28:09.7226640Z] Level=Info, Kind=Begin, Category='System.Web.Http.Filters', Id=800000ad-0002-fb00-b63f-84710c7967bb, Message='Action filter for 'LoginExternal(String signin, String provider)'', Operation=SecurityHeadersAttribute.OnActionExecutedAsync, Status=401 (Unauthorized)
LibLog Information: 0 : [2017-04-05T13:28:09.7236655Z] Level=Info, Kind=End, Category='System.Web.Http.Filters', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=SecurityHeadersAttribute.OnActionExecutedAsync, Status=401 (Unauthorized)
LibLog Information: 0 : [2017-04-05T13:28:09.7246669Z] Level=Info, Kind=End, Category='System.Web.Http.Controllers', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=AuthenticationController.ExecuteAsync, Status=401 (Unauthorized)
LibLog Information: 0 : [2017-04-05T13:28:09.7251836Z] Level=Info, Kind=End, Category='System.Web.Http.MessageHandlers', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=PassiveAuthenticationMessageHandler.SendAsync, Status=401 (Unauthorized)
LibLog Information: 0 : [2017-04-05T13:28:09.7261856Z] Level=Info, Kind=End, Category='System.Web.Http.MessageHandlers', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=DependencyScopeHandler.SendAsync, Status=401 (Unauthorized)
LibLog Information: 0 : [2017-04-05T13:28:09.7271879Z] Sending response, Status=401 (Unauthorized), Method=GET, Url=https://localhost:44396/identity/external?provider=AzureAd&signin=2d92dd18a6106c9b029eb8742d4117a1, Id=800000ad-0002-fb00-b63f-84710c7967bb, Message='Content-type='none', content-length=unknown'
浏览器将无限期地继续等待本地主机。 如果我停止请求并立即再次单击该按钮,一切都会按预期进行。
【问题讨论】:
-
IDSrv3 AuthenticatioinController.cs 中的错误似乎发生在第 330 行,就在之前的 context.Authentication.Challenget(authProp, provider) 然后这个方法立即返回 Unauthorized();
标签: c# authentication azure-active-directory identityserver3