resin-auth
Resin.io session authentication utilities
Role
The intention of this module is to provide low level access to how a Resin.io authentication tokens are parsed and persisted.
THIS MODULE IS LOW LEVEL AND IS NOT MEANT TO BE USED BY END USERS DIRECTLY.
Unless you know what you're doing, use the Resin SDK instead.
Installation
Install resin-auth
by running:
$ npm install --save resin-auth
Documentation
The module returns a class that you use to get an instance of the auth module.
It accepts the following params:
Param | Type | Description |
---|---|---|
options | Object |
options |
options.dataDirectory | string |
the directory to use for storage in Node.js. Ignored in the browser. |
options.tokenKey | string |
the key used to store the last token in the storage. token by default. |
Example
import ResinAuth from 'resin-auth';
const auth = new ResinAuth({
dataDirectory: '/opt/cache/resin',
tokenKey: 'token'
});
-
auth
-
~setKey(key) ⇒
Promise.<void>
-
~hasKey() ⇒
Promise.<Boolean>
-
~removeKey() ⇒
Promise
-
~getType() ⇒
Promise.<TokenType>
-
~getKey() ⇒
Promise.<string>
-
~getAge() ⇒
Promise.<(number|undefined)>
-
~isExpired() ⇒
Promise.<boolean>
-
~isValid() ⇒
Promise.<boolean>
-
~needs2FA() ⇒
Promise.<boolean>
-
~setKey(key) ⇒
Promise.<void>
auth~setKey(key) ⇒ Kind: inner method of auth
Summary: Set the key
Access: public
Param | Type |
---|---|
key | String |
Example
auth.setKey('...').then(() => { ... });
Promise.<Boolean>
auth~hasKey() ⇒ Kind: inner method of auth
Summary: Has a key
Returns: Promise.<Boolean>
- has key
Access: public
Example
auth.hasKey().then((hasKey) => { ... });
Promise
auth~removeKey() ⇒ This promise is not rejected if there was no key at the time of removal.
Kind: inner method of auth
Summary: Remove the key
Access: public
Example
auth.removeKey();
Promise.<TokenType>
auth~getType() ⇒ Kind: inner method of auth
Summary: Gets the key type
Access: public
Example
auth.getType().then((type) => { ... });
Promise.<string>
auth~getKey() ⇒ Kind: inner method of auth
Summary: Gets the key
Access: public
Example
auth.getKey().then((key) => { ... });
Promise.<(number|undefined)>
auth~getAge() ⇒ Kind: inner method of auth
Summary: Gets the token age
Access: public
Example
auth.getAge().then((age) => { ... });
Promise.<boolean>
auth~isExpired() ⇒ Kind: inner method of auth
Summary: Checks if token is expired
Access: public
Example
auth.isExpired().then((expired) => { ... });
Promise.<boolean>
auth~isValid() ⇒ Kind: inner method of auth
Summary: Checks if token format is valid
Access: public
Example
auth.isValid().then((valid) => { ... });
Promise.<boolean>
auth~needs2FA() ⇒ Kind: inner method of auth
Summary: Checks whether 2FA is needed
Access: public
Example
auth.needs2FA().then((needs2FA) => { ... });
Support
If you're having any problem, please raise an issue on GitHub and the Resin.io team will be happy to help.
Tests
Run the test suite by doing:
$ npm test
Contribute
- Issue Tracker: github.com/resin-io-modules/resin-auth/issues
- Source Code: github.com/resin-io-modules/resin-auth
Before submitting a PR, please make sure that you include tests, and that tslint runs without any warning:
$ npm run lint
License
The project is licensed under the Apache 2.0 license.