0

所以我写了这个小函数来刷新用户的令牌:

function refreshToken (refreshToken) {
    const provider = new AWS.CognitoIdentityServiceProvider();
    const params = {
        AuthFlow: 'REFRESH_TOKEN_AUTH',
        ClientId: strapi.config.AWSClientAppId,
        UserPoolId: strapi.config.AWSUserPollId,
        AuthParameters: {
            REFRESH_TOKEN: refreshToken,
        }
    };

    return new Promise(function (resolve, reject) {
        provider.adminInitiateAuth(params, function (err, session) {
            if (err) {
                return reject(err);
            }
            resolve(session);
        });
    });
}

它可以正常工作一段时间,但是一段时间后它开始在下面抛出错误。我不明白为什么会发生这个错误

{ TypeError: Key must be a buffer
at new Hmac (crypto.js:92:16)
at Object.Hmac (crypto.js:90:12)
at Object.hmac (/pipeline/source/node_modules/aws-sdk/lib/util.js:401:30)
at Object.getSigningKey (/pipeline/source/node_modules/aws-sdk/lib/signers/v4_credentials.js:59:8)
at V4.signature (/pipeline/source/node_modules/aws-sdk/lib/signers/v4.js:97:36)
at V4.authorization (/pipeline/source/node_modules/aws-sdk/lib/signers/v4.js:92:36)
at V4.addAuthorization (/pipeline/source/node_modules/aws-sdk/lib/signers/v4.js:34:12)
at /pipeline/source/node_modules/aws-sdk/lib/event_listeners.js:202:18
at finish (/pipeline/source/node_modules/aws-sdk/lib/config.js:313:7)
at /pipeline/source/node_modules/aws-sdk/lib/config.js:331:9
at /pipeline/source/node_modules/aws-sdk/lib/credentials.js:123:23
at Credentials.refresh (/pipeline/source/node_modules/aws-sdk/lib/credentials.js:194:5)
at Credentials.get (/pipeline/source/node_modules/aws-sdk/lib/credentials.js:121:12)
at getAsyncCredentials (/pipeline/source/node_modules/aws-sdk/lib/config.js:325:24)
at Config.getCredentials (/pipeline/source/node_modules/aws-sdk/lib/config.js:345:9)
at Request.SIGN (/pipeline/source/node_modules/aws-sdk/lib/event_listeners.js:179:22) retryDelay: 79.21510223637249 }
4

0 回答 0