【发布时间】:2016-09-27 02:03:10
【问题描述】:
我正在使用以下代码从我的 MVC Web 应用程序中成功获取令牌。但是我不确定如何检索我添加的声明。它们是否应该在与我的令牌相同的响应中返回? 谢谢!
Startup.cs:
app.UseJwtBearerAuthentication(options =>
{
options.AutomaticAuthenticate = true;
options.Audience = "resource_server";
options.Authority = "https://www.example.com/";
options.RequireHttpsMetadata = false;
});
app.UseOpenIdConnectServer(options =>
{
options.ApplicationCanDisplayErrors = true;
options.AllowInsecureHttp = false;
options.Provider = new AuthorizationProvider();
options.TokenEndpointPath = "/connect/token";
});
添加声明:
identity.AddClaim("custom_claim", "value", "token id_token");
foreach (string role in await userManager.GetRolesAsync(user))
{
identity.AddClaim(ClaimTypes.Role, role, "id_token token");
}
这是我的 PostAsync 结果:
{"resource":"resource_server","scope":"openid profile","token_type":"bearer","access_token":"eyJhbGciOiJSU....","expires_in":"3600"}
【问题讨论】:
-
你为什么不用
User.FindFirst("custom_claim").Value? -
我的客户端是一个 Xamarin iOS/Android 应用程序,我认为它没有 asp.net 用户对象。我正在进行 oauth 登录,然后将令牌和声明保留在我的应用中。
标签: c# asp.net asp.net-core openid-connect aspnet-contrib