authentication - 为什么我的 jsreport 身份验证不起作用?
问题描述
我正在尝试https://jsreport.net/learn/authentication:
....
"extensions": {
"authentication": {
"cookieSession": {
"secret": "<your strong secret here>"
},
"admin": {
"username": "admin",
"password": "password"
},
"enabled": true
},
......
我还阅读了以下内容:
启用此扩展时,您需要将标头添加到每个请求。
授权:基本QWxhZGRpbjpvcGVuIHNlc2FtZQ==
哈希基于用户名和密码:base64(用户名:密码)
我尝试同时使用QWxhZGRpbjpvcGVuIHNlc2FtZQ==
并使用https://www.motobit.com/util/base64-decoder-encoder.asp进行编码:admin:password
结果:YWRtaW46cGFzc3dvcmQ=
。在尝试它们时,它们似乎都无法让我访问我的 API。
(请注意,下面的键是我尝试过的上述任何一个)
我尝试过对 jsreport API 进行前端调用: return this.http.post(this.hosturl, parameter, { headers: 'Content-Type': 'application/json', 'Authorization': 'Basic ' + this.key }, responseType: 'blob' });
我还尝试在后端调用 jsreport API:
var data = {
headers: {
"Authorization" : "Basic key"
},
template: { "shortid": shortid },
options: {
preview: preview
}
}
知道为什么它总是在前端(角度)返回未经授权并在后端(快速)提示登录吗?
PS:在用户名的后端API提示:管理员和密码:密码由于某种原因不起作用。
我只设法使用用户名:管理员和密码:密码从 jsreport 工作室登录。
任何想法都值得赞赏。
解决方案
它总是在前端(角度)返回未经授权并在后端(快速)提示登录的原因是错误的实现。
我如何设法解决它:
对于前端:
之后的变量声明constructor(){}
:
key = 'YWRtaW46cGFzc3dvcmQ=';
header = { 'Content-Type': 'application/json', 'Authorization': 'Basic ' + this.key };
服务电话:
return this.http.post(this.hosturl, parameter, { headers: this.header, responseType: 'blob' });
对于后端:
var options = {
uri: 'http://localhost:5488/api/report',
auth: { user: 'admin', password: 'password'},
method: 'POST',
json: data
}
推荐阅读
- excel - vba - 根据定义的值更改单元格的颜色
- dialogflow-es - 如何在对话框流中创建带有日期的自定义实体
- symfony - symfony 4 json_login JWT 401 凭证错误
- python - SQLAlchemy Bakery -Function 需要一定的数组大小
- c++ - 在 C++ 中运行时更改操作
- java - 我可以将列表作为参数传递给 Scala/Java 中以这种方式定义的方法 detectFormatAutomatically(delimitersForDetection:Char*)
- python - 尝试在 Python 中构建一个简单的计算器无法在数学符号之间进行迭代
- google-cloud-firestore - Firestore 安全规则 - 通配符集合名称?
- javascript - 如何在下拉列表中获取除隐藏和提交按钮之外的所有表单字段
- groovy - Groovy AST 方法调用表达式的目标方法未设置