简体   繁体   English

从Owin Api创建后,你如何获得Oauth2 AccessToken?

[英]How do you get the Oauth2 AccessToken after its creation from the Owin Api?

If for some auditing reason I would be asked to store the AccessToken to Db after its creation, is there an Owin API Class that returns the AccessToken ? 如果出于某些审计原因,我会被要求在创建后将AccessToken存储到Db,是否有返回AccessTokenOwin API类

public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
    //check user credentials
    ....
    context.Validated(ticket);
    //Where should I get the generated token?
    }
}

The only workaround I found is to create an Http filter in the Global.Asax that reads the output stream and get the Token from there. 我找到的唯一解决方法是在Global.Asax中创建一个Http过滤器,它读取输出流并从那里获取令牌。

Is there a more elegant way to get it directly from the Owin Api ? 是否有更优雅的方式直接从Owin Api获取它?

Sure you can but you need to use Microsoft.Owin.Security.OAuth version 3.0 not 2.1 and then override TokenEndpointResponse in class OAuthAuthorizationServerProvider as the code below 当然你可以,但你需要使用Microsoft.Owin.Security.OAuth版本3.0而不是2.1,然后在类OAuthAuthorizationServerProvider中覆盖TokenEndpointResponse作为下面的代码

public override Task TokenEndpointResponse(OAuthTokenEndpointResponseContext context)
    {
        var accessToken = context.AccessToken;
        return Task.FromResult<object>(null);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM