簡體   English   中英

豐富ASP.Net承載令牌格式

[英]Enrich ASP.Net bearer token format

我已經設置了一個支持承載令牌的ASP.NET WebApi項目,如下所示:

var oAuthServerOptions = new OAuthAuthorizationServerOptions
{
    AllowInsecureHttp = true,
    TokenEndpointPath = new PathString("/token"),
    AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
    Provider = new SimpleAuthorizationServerProvider()
};

var oAuthBearerOptions = new OAuthBearerAuthenticationOptions();

app.UseOAuthAuthorizationServer(oAuthServerOptions);
app.UseOAuthBearerAuthentication(oAuthBearerOptions);

當我向令牌端點發出請求時,我有這個答案

{
    "access_token":"GST9UwSuesiYhkezr94K4xwuzvNQ",
    "token_type":"bearer",
    "expires_in":86399
}

有沒有辦法用這樣的附加字段來豐富令牌?

{
    "access_token":"GST9UwSuesiYhkezr94K4xwuzvNQ",
    "token_type":"bearer",
    "expires_in":86399,
    "username":"user@mail.com"
}

那么這是解決方案:

在您的類中繼承自OAuthAuthorizationServerProvider

public override async Task TokenEndpoint(OAuthTokenEndpointContext context)
{
    context.AdditionalResponseParameters.Add("username", "user@mail.com");

    return Task.FromResult<object>(null);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM