【问题标题】:Overriding TokenEndPoint in AspNet.Security.OpenIdConnect.Server在 AspNet.Security.OpenIdConnect.Server 中覆盖 TokenEndPoint
【发布时间】:2016-03-08 14:03:42
【问题描述】:

与此帖子相关的问题在这里:Configure the authorization server endpoint

使用上面的例子我可以得到令牌。以前可以通过骑车获得更多信息

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

谢谢!

【问题讨论】:

    标签: c# asp.net-core openid openid-connect aspnet-contrib


    【解决方案1】:

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

    您可以这样做:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-05
    • 2016-11-12
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 2012-01-28
    相关资源
    最近更新 更多