identityserver4 - JS 报告服务器控制台错误:授权服务器在其响应中没有“用户名”字段,令牌假定为无效
问题描述
我的带有客户端 ui 应用程序的 js 报表服务器正在使用通过在身份服务器中添加一个声明(例如 Claim('username', 'user name value'))提交的用户名。4 版本 1.1。但是最近客户端已将 identityserver 4 版本升级到 2.2.0 和 netcoreapp2.1 。
现在客户端 ui 应用程序收到“未经授权”错误。当我在本地运行应用程序时,我在 jsreport 服务器控制台中看到一个错误:错误:授权服务器在其响应中没有“用户名”字段,令牌假定为无效。
我试图在示例中找到解决方案: https ://github.com/bjrmatos/jsreport-with-authorization-server-sample但他们尚未升级最新的.net 核心和身份服务器的示例,我看到了节点Node.js 示例链接“ https://github.com/IdentityServer/IdentityServer4.Samples/tree/release/NodeJsApi ”不存在。所以我无法解决这个问题。有人可以帮我吗?
提前致谢。
解决方案
我找到了解决此错误的解决方案,方法是添加带有用户名的声明类型并在 api 资源范围内声明:
new ApiResource
{
Name="jsreportscope",
DisplayName = "JavaScript based reporting platform",
Scopes=
{
new Scope()
{
Name="jsreportscope",
UserClaims = new List<string>(){"username" }
}
},
UserClaims = new List<string>(){"username"},
ApiSecrets = { new Secret("yoursecret".Sha256()) },
}
但是现在它解决了之前的问题,我通过添加与用户名字段值的值与身份服务器 1.1 版本匹配的声明类型来修复,但现在我们已将身份服务器版本升级到 2.1 并再次收到错误。它能够授权身份服务器的任何用户访问报告。这是我正在使用的jsreport.config.js代码:
{
"store": { "provider": "fs" },
"httpPort": 5004,
"allowLocalFilesAccess": true,
"extensions": {
"authentication": {
"cookieSession": {
"secret": "<your strong secret>"
},
"admin": {
"username": "IdentityServer4User@domain.com",
"password": "Password"
},
"authorizationServer": {
"tokenValidation": {
"endpoint": "http://localhost:5000/connect/introspect",
"usernameField": "username",
"activeField": "active",
"scope": {
"valid": ["jsreportscope"]
},
"auth": {
"type": "basic",
"basic": {
"clientId": "jsreport",
"clientSecret": "yoursecret"
}
}
}
},
"enabled": true
},
"authorization": {
"enabled": true
},
"sample-template": {
"createSamples": true
}
}
}
但是现在我可以登录并从报表服务器访问报表,如果仅由用户IdentityServer4User@domain.com登录,任何其他用户都会收到未经授权的错误。在报表服务器控制台中,错误显示如下:
错误:从授权服务器返回的用户名“OtherIdentityServer4User@domain.com”不是 jsreport 用户。我不想将所有身份服务器用户添加到 js 报表服务器。
推荐阅读
- r - R脚本,如何对因子值进行分组和最大值?
- c++ - C ++将模板类函数传递给另一个函数后无法调用
- reactjs - React 功能组件 - 将处理程序绑定到数组
- python - 为什么我的 discord.py 机器人不响应 on_message 事件?
- architecture - 当有许多 Web 服务器应用程序实例正在运行时,通过持久连接向客户端发送消息
- qt - 如何在 QML 的 ColumnLayout 中使用自己的对象?
- node.js - 无法读取未定义 discord.js 的属性用户名
- flutter - 如何在不改变所有内容的情况下连续格式化文本
- reactjs - React:方法在数据加载之前完成
- python - pyinstaller 从 .py 文件运行 --add-data 无效