0

我按照这里的例子https://stormpath.com/blog/the-ultimate-guide-to-mobile-api-security

并在这里获取访问令牌

https://support.stormpath.com/hc/en-us/articles/225610107-How-to-Use-Stormpath-for-Token-Management

"use strict";

import { ApiKey } from 'stormpath'; 
import { Client } from 'stormpath';

let apiKey = new ApiKey(process.env.STORMPATH_API_KEY_ID,
     process.env.STORMPATH_API_KEY_SECRET);

let spClient = new Client({apiKey: apiKey });

spClient.getApplication(process.env.STORMPATH_APPLICATION_HREF,
   function(err, app) {

    var authenticator = new OAuthAuthenticator(app);

    authenticator.authenticate({
        body: {
            grant_type: 'password',
            username: username,
            password : password
        }
    }, function (err, result) { 
        if (!err) console.log(err);
        res.json(result.accessTokenResponse);
    });
});

我能够获得一个access_token。我使用此令牌通过 Header Authorization Bearer {access_token} 访问我的 api

但是,当我放入中间件时stormpath.apiAuthenticationRequired,我不断收到此警告,并且我的 api 返回 401

(node:57157) DeprecationWarning: JwtAuthenticator is deprecated, please use StormpathAccessTokenAuthenticator instead.
4

0 回答 0