本文介绍了覆盖AspNet.Security.OpenIdConnect.Server中的TokenEndPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

与此帖子相关的问题:配置授权服务器端点.

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);
        }

您如何在

public override Task TokenEndpoint(TokenEndpointContext context){
}

谢谢!

推荐答案

您最好的选择是直接使用ApplyTokenResponse事件更新返回给客户端应用程序的JSON有效负载.与AdditionalResponseParameters不同,它允许您添加或删除几乎所有内容:对象,数组,字符串,整数...

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);
}

这篇关于覆盖AspNet.Security.OpenIdConnect.Server中的TokenEndPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:45