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

任何人都可以帮助我按照以下格式将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/

相关文章:

authentication - 我可以使用带有额外 header 的 git-tfs 吗?

react-native - React Native Webview OnLoad 调用了两次

firebase - 如何避免在 firebase ML Kit 的人脸检测 API 中捕获图像模糊

python - 如何在 tensorflow 2.0 中为自定义量化反向传播?

git - 在 Synology NAS 上启用 Gitlab LFS

python - WinError 10061 由于目标机器主动拒绝,无法建立连接

python-3.x - 重复的日志 Flask - Google Cloud Logging

javascript - 如何访问 react-image-gallery 中的 slideToIn

python - 无需安装即可导入 Python 库

reactjs - 将 Ant 设计表导出为 pdf 格式