本文介绍了自承载令牌JSON结果在ASP.NET的WebAPI 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我演练和承载令牌公布如下JSON。
I walkthrough this official ASP.NET tutorial, and the bearer token is published as below JSON.
{
"access_token":"boQtj0SCGz2GFGz[...]",
"token_type":"bearer",
"expires_in":1209599,
"userName":"Alice",
".issued":"Mon, 14 Oct 2013 06:53:32 GMT",
".expires":"Mon, 28 Oct 2013 06:53:32 GMT"
}
我想沿与上述resul以减少来自客户端的请求的数目增加用户简档属性。的例子是如下面...
I'd like to add user profile properties along with the above resul in order to reduce number of requests from clients. The example is as below...
{
"access_token":"boQtj0SCGz2GFGz[...]",
"token_type":"bearer",
"expires_in":1209599,
"userName":"Alice",
".issued":"Mon, 14 Oct 2013 06:53:32 GMT",
".expires":"Mon, 28 Oct 2013 06:53:32 GMT",
"Notifications":35,
"IsEventMember":true,
"Promotion":324372
}
我使用的OAuth的提供者是从默认的ASP.NET模板( ApplicationOAuthProvider.cs
)和 OAuthOption
是下文。
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
我如何做?
请注意,我的问题是,从的不同。
Note that my question is different from adding extra claims.
推荐答案
那么这里是解决方案:
public override async Task TokenEndpoint(OAuthTokenEndpointContext context)
{
context.AdditionalResponseParameters.Add("username", "user@mail.com");
return Task.FromResult<object>(null);
}
这篇关于自承载令牌JSON结果在ASP.NET的WebAPI 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!