Useful methods to extend Auth driver.
npm i auth-driver-utils
Expects a valid instance of Auth driver to extend upon.
Maps Auth driver's .get
method to .read
(for better CRUD naming) and applies
.parse
to the result.
Extends Auth driver's .search
method by applying .parse
to each result.
Converts an Entity from the Auth Service into an Authorization instance with helper methods (see below).
Creates a new entity within the Auth Service, then parses the new entity record into an Authorization instance. Note: You must provide the object in the Auth Service format (refer entity schema), not a Authorization object.
Provides direct access to the Authorization class, useful for testing permissions.
const Authorization = require('auth-driver-utils').Authorization;
new Authorization(<id>, <role>, <permissions>)
Permissions must be in the Authorization format e.g.
permissions: {
<entity>: [<type>, <type>]
...
}
Checks if the passed id matches the id of the auth user instance.
Checks if user (of
) has permission (perm
) to do something.
Adds permission (perm
) to user (of
). Useful for when dealing with legacy
permissions and metadata.