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
?
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.
Is there a more elegant way to get it directly from the 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
public override Task TokenEndpointResponse(OAuthTokenEndpointResponseContext context)
{
var accessToken = context.AccessToken;
return Task.FromResult<object>(null);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With