![](/img/trans.png)
[英]Microsoft.Owin.Security.Oauth Bearer Token Authorization Interception
[英]get access token via asp.net Microsoft.Owin.Security.OAuth
根據下面的參考..,
我得到以下代碼以創建access_token。
var ticket = new AuthenticationTicket(identity, props);
OAuthGrantResourceOwnerCredentialsContext.Validated(ticket);
但不幸的是,此Validated(ticket)
方法不會返回自動神奇生成的access_token。
我想要得到的就像下面的代碼。
string _access_token = OAuthGrantResourceOwnerCredentialsContext.Validated(ticket);
System.out.println("Access_token ="+_access_token);
請讓我得到您的建議。
您必須重寫OAuthAuthorizationServerProvider類的方法TokenEndpointResponse ,並獲取上下文的屬性AccessToken 。
public class ApplicationOAuthProvider : OAuthAuthorizationServerProvider
{
public override Task TokenEndpointResponse(OAuthTokenEndpointResponseContext context)
{
var token = context.AccessToken;
return base.TokenEndpointResponse(context);
}
}
當然,您必須致電自定義提供商
static Startup()
{
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60),
AllowInsecureHttp = true,
RefreshTokenProvider = new ApplicationRefreshTokenProvider(),
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.