【发布时间】:2015-08-31 07:27:59
【问题描述】:
使用 OpenId Connect 中间件 (dnxcore50; 1.0.0-beta6-* coreclr x64) 处理 AAD SSO ...
app.UseCookieAuthentication(options => { options.AutomaticAuthentication = true; });
app.UseOpenIdConnectAuthentication(options => {
options.ClientId = ClientId;
options.Authority = Authority;
options.PostLogoutRedirectUri = PostLogoutRedirectUri;
options.AutomaticAuthentication = true;
options.SecurityTokenValidators = new[] { new UnsafeJwtSecurityTokenHandler() };
options.Notifications = new OpenIdConnectAuthenticationNotifications {
AuthenticationFailed = OnAuthenticationFailed,
AuthorizationCodeReceived = OnAuthorizationCodeReceived
};
});
在OnAuthorizationCodeReceived,以这种方式获取 Graph API 的上下文...
string userObjectId = notification.AuthenticationTicket.Principal.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
ClientCredential credential = new ClientCredential(ClientId, AppKey);
AuthenticationContext authContext = new AuthenticationContext(Authority);
AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(notification.Code, new Uri(BaseAddress), credential, "https://graph.windows.net");
适用于 dnx451 1.0.0-beta4 clr x86,但不适用于 dnxcore50 1.0.0-beta6-* coreclr x64
The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.Authenticator' threw an exception.
ClientId、AppKey、Authority、notification.Code 和 BaseAddres 的值应该没问题……它们在两个运行时之间没有改变。依赖是...
"Microsoft.IdentityModel.Protocol.Extensions": "2.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-*",
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.1.203031538-alpha",
"Microsoft.Framework.ConfigurationModel": "1.0.0-*",
"Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-*",
"Microsoft.AspNet.Identity": "3.0.0-*",
"Microsoft.AspNet.Http": "1.0.0-*"
我也在AzureAD/azure-activedirectory-library-for-dotnet 发帖,但那里的答案似乎很慢。如果在这里回答,我会在那里更新+关闭。
【问题讨论】:
-
btw - 我确实将我的 ActiveDirectory 包升级到 3.3.205061641-alpha;没有骰子...问题仍然存在。
标签: adal