gpt4 book ai didi

c# - 覆盖 AspNet.Security.OpenIdConnect.Server 中的 TokenEndPoint

转载 作者:太空狗 更新时间:2023-10-29 23:21:24 26 4
gpt4 key购买 nike

此处与此帖子相关的问题:Configure the authorization server endpoint .

使用上面的示例,我可以获得 token 。以前可以通过骑车获得额外的信息

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 不同,它允许您添加或删除几乎任何东西:对象、数组、字符串、整数...

以下是您可以如何做到这一点:

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

关于c# - 覆盖 AspNet.Security.OpenIdConnect.Server 中的 TokenEndPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34074787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com