在哪里存储JWT客户端凭证授权

我有一个NodeJS快速应用程序,通过客户端凭据授权身份validation到身份validation服务器。 我收到的令牌用于从API加载数据。

在整个应用程序中存储令牌的最佳实践是什么?

请注意,JWT不是用户特定的,因为我的Express App是客户端。

我试图避免坚持返回的令牌,只保留在内存中,因为客户端凭据授权使您可以相对容易地获取新的令牌,而无需用户交互。

但是,如果这是有问题的,那么我会说:在客户端凭证旁边,因为客户端凭据至less与JWT令牌一样敏感。

我将把它存储在内存中。 通常我会写一个单例模块来处理它。

auth.js:

class Auth { getToken() { // check if we has token already and that token isn't expired if (this.token && !isExpired(this.token)) { return Promise.resolve(this.token); } // if not we call API for the new token then return the new token return asyncCallApiForToken(); } } module.exports = new Auth(); 

main.js

 const auth = require('./auth.js) auth.getToken() .then(token => { // we got token here }