C# 在ASP.NET WebApi 2中自定义承载令牌JSON结果
我在演练中看到,承载令牌发布如下C# 在ASP.NET WebApi 2中自定义承载令牌JSON结果,c#,json,asp.net-web-api,access-token,asp.net-identity,C#,Json,Asp.net Web Api,Access Token,Asp.net Identity,我在演练中看到,承载令牌发布如下 { "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"
}
我想在上面的结果中添加用户配置文件属性,以减少来自客户端的请求数量。示例如下所示
{
"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模板(ApplicationAuthProvider.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
};
我怎样才能做到
请注意,我的问题不同于。好的,下面是解决方案:
public override async Task TokenEndpoint(OAuthTokenEndpointContext context)
{
context.AdditionalResponseParameters.Add("username", "user@mail.com");
return Task.FromResult<object>(null);
}
public重写异步任务令牌端点(OAuthTokenEndpointContext)
{
AdditionalResponseParameters.Add(“用户名”user@mail.com");
返回Task.FromResult(空);
}
我发现我的问题重复了: