Where to Store Grant Credentials JWT Client Credentials

I have a NodeJS Express application that authenticates to an Auth server by providing client credentials. The token used is used to load data from the API.

What is the best practice for storing a token in an application?

Please note that JWT is user independent, as my Express application is a client.

+4
source share
2 answers

I will keep it in my memory. Usually I will write a singleton module to process it.

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
    }
+2
source

, .

, : , , JWT.

+2

Source: https://habr.com/ru/post/1690545/


All Articles