我希望在用户登录成功后,在我的 Web 应用程序的右上角显示用户名。 我想将其与 bearer 令牌返回的 JSON 一起发送。 为了生成令牌身份验证,我正在使用 ASP.NET web API 和 Owin middlehawe。
{
"access_token": "blah",
"token_type": "bearer",
"expires_in": 599
}
我希望返回结果如下
{
"access_token": "blah",
"token_type": "bearer",
"expires_in": 599,
"displayusername":"Hi Mundo"
}
我尝试过使用声明,但是没有得到想要的结果。
我尝试使用身份验证属性,但是不起作用。
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
if (validation works)
{
// add claims
var moreInfo = new AuthenticationProperties(new Dictionary<string, string> { { "username", "Don"}, { "Department","MIS"} });
var ticket = new AuthenticationTicket(identity, moreInfo);
context.Validated(ticket);
}
else
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
}
}
我如何向owin bearer token返回的json中添加更多的值?