首页 > 解决方案 > 为什么我的 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 工作室登录。

任何想法都值得赞赏。

标签: authenticationjsreport

解决方案


它总是在前端(角度)返回未经授权并在后端(快速)提示登录的原因是错误的实现

我如何设法解决它:

对于前端:

之后的变量声明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
    }

推荐阅读