c# - Duende身份服务器: How to return external provider tokens also to the Angular/WPF/MVC client along with Duende tokens

标签 c# asp.net .net duende-identity-server duende

我正在使用 Duende Identity 服务器,并且我有一个外部身份验证提供商(比如 google)。登录 google 时,我们会从 google 获取 token ,我们可以利用它来调用一些 google API。

我还需要通过 Duende token 端点将 google token 返回到客户端(Angular/WPF/MVC 等)。

我可以从代码中看到 Duende token 端点响应具有自定义属性,但我不知道如何或从哪里插入我的值。

From Duende Source Code

internal class ResultDto
{
    public string id_token { get; set; }
    public string access_token { get; set; }
    public int expires_in { get; set; }
    public string token_type { get; set; }
    public string refresh_token { get; set; }
    public string scope { get; set; }

    [JsonExtensionData]
    public Dictionary<string, object> Custom { get; set; }
}

我想查看一些关于如何通过现有 Duende 功能向此自定义属性添加值的代码片段或说明。

最佳答案

如果您需要自定义 token 响应,您可以ICustomTokenResponseGenerator(它适用于身份服务器3,如果您使用的是版本4及更高版本,我不确定,但它应该是ITokenResponseGenerator):

class CustomTokenResponseGenerator : ICustomTokenRequestValidator
{
    public Task<TokenResponse> GenerateAsync(ValidatedTokenRequest request, TokenResponse response)
    {
        response.Custom.Add("custom_field", "custom data");      
        return Task.FromResult(response);
    }
}

然后用工厂添加它:

 factory.CustomTokenResponseGenerator = new Registration<ICustomTokenResponseGenerator, CustomTokenResponseGeneratorService>();

关于c# - Duende身份服务器: How to return external provider tokens also to the Angular/WPF/MVC client along with Duende tokens,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75092728/

相关文章:

c# - 使用 Lambda 获取属性名称列表

C# - 验证模拟(MoQ)属性的方法是用部分字符串作为参数调用的

c# 从 SQL 查询构建非常大的文本文件

ASP.NET MVC 5 URL 取决于选择

c# - 属性的自定义异常 - 如何在符合 CA 规则的同时确保属性不为空?

c# - 如何将 Process.Start() 与 unicode 符号(例如😜)一起使用

c# - 处理和存储耗时

c# - 将相同的标签分组并一起更改文本 - c#/Javascript

.net - 使用 Active Directory 进行 .NET 中的用户组和角色管理

c# - 在运行时使用和调用 SOAP Web 服务 - 来自 WSDL 文件的动态 Web 服务客户端