This module is used as an internal front end package that allows us to authenticate to our global authentication micro service.
For now, snapp-auth-proxy is highly dependent to our closed-source authentication micro service. We may consider open sourcing it in the future.
npm install --save snapp-auth-proxy
or yarn add snapp-auth-proxy
First thing you need to do is set the server URL by doing;
import { Config } from 'snapp-auth-proxy';
Config.url = 'https://authproxyurl.com/'
Once you've done that, you will be able to call the following classes and methods
You must define the user and keep the reference to it among your app's lifecycle
import { Authentication } from 'snapp-auth-proxy';
const user = new Authentication(); // Keep a reference to the user variable
await user.authenticate('[email protected]', 'yourpassword');
// returns true/false
await user.isAuthenticated();
// returns true/false
user.logout();
user.permissions.listOf('microServiceName')
// returns an array of actions authorized, for instance: ['edit.post', 'create.post']
user.permissions.on('microServiceName').isAuthorizedTo('edit.post');
// returns true/false
This method is useful to provide access to different types of users.
For example, viewing a post in you blog app might be authorized to people who can manage.posts
, manage.everything
, or just view.post
// You can also check authorization again an array of permissions
user.permissions.on('microServiceName').isAuthorizedToDoAnyOf([
'manage.posts',
'manage.everything',
'view.post',
]);
user.getHeaders('microServiceName');
npm install
npm test
npm run build