Return more info to the client using OAuth Bearer Tokens Generation and Owin in WebApi

前端 未结 2 1989
无人及你
无人及你 2020-12-02 06:04

I have created a WebApi and a Cordova application. I am using HTTP requests to communicate between the Cordova application and the WebAPI. In the WebAPI, I\'ve implemented O

2条回答
  •  既然无缘
    2020-12-02 06:25

    My recommendation is not to add extra claims to the token if not needed, because will increase the size of the token and you will keep sending it with each request. As LeftyX advised add them as properties but make sure you override TokenEndPoint method to get those properties as a response when you obtain the token successfully, without this end point the properties will not return in the response.

     public override Task TokenEndpoint(OAuthTokenEndpointContext context)
        {
            foreach (KeyValuePair property in context.Properties.Dictionary)
            {
                context.AdditionalResponseParameters.Add(property.Key, property.Value);
            }
    
            return Task.FromResult(null);
        }
    
    
    

    You can check my repo here for complete example. Hope it will help.

    提交回复
    热议问题