如何使用 NodeJS 与 Mocha 和 request-promise 通过一个会话通过身份验证和授权?

问题描述

我是这个框架的新手,我已经编写了一个仅用于身份验证端点的脚本,它是成功的。不知何故,我需要在同一个会话上使用授权端点,因为要完成主要请求目标,需要同时获取 200 个。 Authenticate - 返回令牌(有效期为 15 秒),令牌本身需要通过以授权主体。我现在正在努力实现这一点。有人知道如何实现吗?

it('should...',async function() {
        var options = {
            method: generic.METHODS.post,url: `${generic.url}/authenticate`,//this return JSON responce with token.
            body: {
                username: `${generic.credentials.username}`,password: `${generic.credentials.password}`,},headers: {
                accept: "content-type: application/json",method: generic.METHODS.post,url: `${generic.url}/authorize`,body: {
//somehow to authorize I need to pass here that token from authenticate endpoin
                token: `"${token}"`
            },resolveWithFullResponse: true,json: true
        };

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)