c# - 如何将数据(数组)添加到 Identityserver 4 生成的 jwt token

标签 c# asp.net-core oauth identityserver4

任何人都可以帮助我按照以下格式将array 添加到 identityserver4jwt token 中。

如果数组不包含数据:{ "custom_data": [] }
如果数组包含一个元素:{ "custom_data": ["one_element"]}
如果数组包含多个元素:{ "custom_data": ["first element","second element"]}

我尝试使用 IProfileService 并使用 Claims
添加数据 示例代码:

foreach (string element in my_array) {
  userClaims.Add(new Claim("custom_data" , element));
}

但在那种情况下,我得到的结果如下:

if array contains no data : { } 这里我没有得到任何数据
如果数组包含一个元素:{ "custom_data": "one_element"} 这里我将它作为一个字符串
如果数组包含多个元素:{ "custom_data": ["first element","second element"]} 这里我的方法是正确的

最佳答案

我会查看 this发布 AB 遵循 OAuth 2.0 for Browser-Based Apps 的建议文档:

To avoid the risks inherent in handling OAuth access tokens from a purely browser-based application, implementations may wish to move the authorization code exchange and handling of access and refresh tokens into a backend component.

The backend component essentially becomes a new authorization server for the code running in the browser, issuing its own tokens (e.g. a session cookie). Security of the connection between code running in the browser and this backend component is assumed to utilize browser-level protection mechanisms.

In this scenario, the backend component may be a confidential client which is issued its own client secret.

关于c# - 如何将数据(数组)添加到 Identityserver 4 生成的 jwt token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60863413/

相关文章:

c# - 来自开放 API 的 .Net 解析器 JSON

c# - Membership(+ roles) VS session state VS 表单认证

c# - 使用 HttpClient 时如何不排除 Content-Type 中的字符集?

c# - 色盲和颜色。 VS2019 文本编辑器的哪些元素与 C# 语言有关?

c# - 在被测系统上调用方法

c# - WebClient.CancelAsync — 文件仍在下载

entity-framework - 在 EF Core 中自动设置每条记录的创建和修改日期的问题

javascript - Instagram 身份验证 API 不返回访问 token

java - 无法在 Android 上使用 XOAUTH 连接到 Gmail IMAP

python - Django 全授权 Slack : Redirect URL as https instead of http and Social Network Login Failure