Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding TokenEndPoint in AspNet.Security.OpenIdConnect.Server

question related to this post here: Configure the authorization server endpoint.

Using the above example I am able to get token. previously it was possible to get additional information by over riding

public override Task TokenEndpoint(OAuthTokenEndpointContext context)
        {
            foreach (KeyValuePair<string, string> property in context.Properties.Dictionary)
            {
                context.AdditionalResponseParameters.Add(property.Key, property.Value);
            }

            return Task.FromResult<object>(null);
        }

how do you achieve that in the current implementation of

public override Task TokenEndpoint(TokenEndpointContext context){
}

Thanks!

like image 592
BHR Avatar asked Dec 03 '15 19:12

BHR


1 Answers

Your best option is to directly use the ApplyTokenResponse event to update the JSON payload returned to the client application. Unlike AdditionalResponseParameters, it allows you to add - or remove - virtually anything: objects, arrays, strings, integers...

Here's how you can do that:

public override Task ApplyTokenResponse(ApplyTokenResponseContext context)
{
    // Only add the custom parameters if the response is not a token error response.
    if (string.IsNullOrEmpty(context.Error))
    {
        context.Response["custom-property-1"] = "custom-value";

        context.Response["custom-property-2"] = JArray.FromObject(new[]
        {
            "custom-value-1",
            "custom-value-2"
        });
    }

    return Task.FromResult(0);
}
like image 199
Kévin Chalet Avatar answered Sep 29 '22 06:09

Kévin Chalet