fame-auth-lib
v0.0.2
Published
FAME authentication library
Downloads
3
Readme
Fame Auth Lib
The Fame Auth Lib is an authentication library for BE services inside the project FAME. It should used to authorize the express routes inside your project.
This library checks whether the role is present in the token and is valid. It is also possible to pass an array of roles, the library will check if at least one of them is valid.
Requirements
- Node project
- Express
Installation
To install the Fame Auth Lib, simply run the following command:
npm install fame-auth-lib
Usage
Import the library in this way:
import {Auth} from "fame-auth-lib"
Instantiate the constructor passing the authorization url
this.auth = new Auth(this.authUrl);
To use the Fame Auth Lib in your project, follow this test case:
- Start using the library's functions:
test('Token should be valid', async () => {
const auth: Auth = new Auth(authUrl);
const result = await auth.isAuthorized(TOKEN);
expect(result).toEqual(true);
});
test('ADMIN should be authorized', async () => {
const auth: Auth = new Auth(authUrl);
const result = await auth.isAuthorized(TOKEN, [Role.ADMIN]);
expect(result).toEqual(false);
});
test('OPERATOR or ADMIN should be authorized', async () => {
const auth: Auth = new Auth(authUrl);
const result = await auth.isAuthorized(TOKEN, [Role.OPERATOR, Role.ADMIN]);
expect(result).toEqual(true);
});