【问题标题】:Why does my jsreport Authentication wasn't working?为什么我的 jsreport 身份验证不起作用?
【发布时间】:2019-07-19 13:07:45
【问题描述】:

我正在尝试https://jsreport.net/learn/authentication:

....
  "extensions": {
    "authentication": {
      "cookieSession": {
        "secret": "<your strong secret here>"
      },
      "admin": {
        "username": "admin",
        "password": "password"
      },
      "enabled": true
    },
......

我还阅读了以下内容:

在启用此扩展时,您需要在每个请求中添加标头。

授权:基本 QWxhZGRpbjpvcGVuIHNlc2FtZQ==

其中哈希基于用户名和密码:base64(username:password)

我尝试同时使用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 提示用户名:管理员和密码:密码由于某种原因不起作用。

我只设法使用用户名:admin 和密码:password 从 jsreport 工作室登录。

任何想法都值得赞赏。

【问题讨论】:

    标签: authentication jsreport


    【解决方案1】:

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

    我是如何解决的:

    对于前端:

    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
        }
    

    【讨论】:

    • 事实上,当我测试生产代码时,我的拦截器正在拦截所有返回失败的身份验证请求。当使用this answer 时,我能够忽略这个特定请求的拦截器。
    猜你喜欢
    • 2014-01-28
    • 2019-08-04
    • 2019-10-31
    • 2019-04-08
    • 2014-06-08
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    相关资源
    最近更新 更多