我想在用户成功登录后返回用户名,以显示在我的网络应用程序的右上角。我想用令牌返回的 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"
}
我已经尝试过索赔,但那些没有给出我想要的结果。
我尝试使用 AuthenticationProperties 但不起作用
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 不记名令牌返回的 json 添加更多值?