Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

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?

like image 781
systempuntoout Avatar asked Sep 27 '14 05:09

systempuntoout


1 Answers

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);
    }
like image 117
Taiseer Joudeh Avatar answered Oct 23 '22 16:10

Taiseer Joudeh