我演练this official ASP.NET tutorial,并且承载令牌发布如下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"
}
我想将用户配置文件属性与上述结果一起添加,以减少来自客户端的请求数量。示例如下。
{
"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
};
我该怎么做?
请注意,我的问题与adding extra claims不同。
这里是解决方法:
public override async Task TokenEndpoint(OAuthTokenEndpointContext context)
{
context.AdditionalResponseParameters.Add("username", "[email protected]");
return Task.FromResult<object>(null);
}