This framework simlifies integration with the authorization framework, which is combined with the session config. After cloning the repository, please run the following command on the command line, in order to install the required node packages:
npm install
Create the configuration object with following fields.
const TOKEN_AUTH_CONFIG = {
"realm": <auth_server_realm_of_the_application>,
"auth-server": <auth_server_url>,
"client-id": <application client_id>,
"client-secret": <application client_secret>,
"session-name": <session_name>,
"session-secret": <session_secret>
}
Afterwards, all is necessary to pass Express application context and the config above.
const TokenAuthController = require("token-auth-framework")
...
const tokenAuth = new TokenAuthController()
tokenAuth.initialize(app, TOKEN_AUTH_CONFIG)
If the user is not authorized, will redirected to the authorization server. Logout path is "/logout" To fetch the role info of the user use: "req.user.role".