【发布时间】:2016-10-27 12:24:02
【问题描述】:
我正在关注本教程link。我可以使用 azure ad 用户登录。但是一旦用户获得身份验证。我们希望将其存储到身份声明中以进行身份验证。 我们正在将 Asp.net MVC 应用程序迁移到 asp.net core MVC 1.0。在 Asp.net MVC 应用程序中,我们正在添加这样的声明
context.AuthenticationTicket.Identity.AddClaim(new System.Security.Claims.Claim("urn:Projectname:access_token", result.AccessToken, XmlSchemaString, "Projectname"));
我想知道如何在上面的教程中添加声明身份。
代码片段
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
ClientId = clientId,
ClientSecret = clientSecret,
Authority = authority,
CallbackPath = Configuration["AzureAd:AuthCallback"],
ResponseType = OpenIdConnectResponseType.CodeIdToken,
PostLogoutRedirectUri = "/signed-out",
Events = new OpenIdConnectEvents()
{
OnAuthorizationCodeReceived = async context =>
{
var request = context.HttpContext.Request;
var currentUri = UriHelper.BuildAbsolute(request.Scheme, request.Host,request.PathBase, request.Path);
var credential = new ClientCredential(clientId, clientSecret);
var authContext = new AuthenticationContext(authority, AuthPropertiesTokenCache.ForCodeRedemption(context.Properties));
var result = await authContext.AcquireTokenByAuthorizationCodeAsync(
context.ProtocolMessage.Code, new Uri(currentUri), credential, resource);
// In result variable , we are getting the AccessToken and we want to add this into claims identity here.
context.HandleCodeRedemption();
}
}
});
更新
我们正在存储令牌、域名(从数据库中获取)、用于中间层身份验证的租户信息。就像在非常控制器的操作方法中一样,我们从声明中获取存储的信息。 类似的东西(旧的 Asp.net MVC 应用程序代码)。
在 Startup.Auth.cs 类中
在所有控制器动作方法中
我们正在将 Asp.net MVC 应用程序迁移到 asp.net core MVC 1.0。那么在 asp.net 核心中是否有任何等效的方法来添加声明。我关注This sample。我可以使用 azure ad 用户登录。但是一旦用户获得身份验证。我们希望将其存储到身份声明中以进行身份验证(中间层)。
【问题讨论】:
标签: azure asp.net-core-mvc claims-based-identity openid-connect katana