【发布时间】:2017-06-16 21:11:30
【问题描述】:
我正在使用 Web Api 2 并实现了基于自定义令牌的身份验证。它工作正常,但我想获得一些额外的属性值作为响应。即使我添加了新声明并添加了新属性以获取它们的值作为响应,但我仍然只得到三个响应值,即“access_token”、“token_type”和“expires_in”。我怎样才能得到更多的价值作为回应。 这是我的代码:
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
if(context.UserName == "user" && context.Password=="user")
{
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
identity.AddClaim(new Claim(ClaimTypes.Role, "Administrators"));
identity.AddClaim(new Claim("MyClaim", "I don't know"));
var props = new AuthenticationProperties(new Dictionary<string, string>
{
{ "name", "John" },
{ "surname", "Smith" },
{ "age", "40" },
{ "gender", "Male" }
});
var ticket = new AuthenticationTicket(identity, props);
context.Validated(ticket);
}
else
{
context.SetError("Invalid_Grant", "Provided username and password is incorrect");
return;
}
}
这是我得到的输出
{
"access_token": "xxxxx", "token_type": "承载者", “expires_in”:86399 }
【问题讨论】:
-
哪个类包含这个方法GrantResourceOwnerCredentials
-
@Aravind 公共类 AuthorizationServerProvider : OAuthAuthorizationServerProvider{-----}
标签: c# oauth-2.0 asp.net-web-api2 owin bearer-token