
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
An authentication library that uses JWT for access and refresh tokens with sensible defaults.
An authentication library that uses JWT for access and refresh tokens with sensible defaults.
npm install authomatic
Please create an issue if you need another store.
const Store = require('authomatic-redis');
const Authomatic = require('authomatic');
const store = Store();
const authomatic = new Authomatic({store});
// Use authomatic functions
npm test
The example has been updated to reflect all the new changes.
Promise.<Tokens>
Returns access and refresh tokens
String
Verifies token, might throw jwt.verify errors
Promise.<Tokens>
Issues a new access token using a refresh token and an old token (can be expired).
Promise.<Boolean>
Invalidates refresh token
Promise.<Boolean>
Invalidates all refresh tokens
String
a string greater than 20 characters
String
Regular JWT token. Its payload looks like this:
{
"t": "Authomatic-AT",
"uid": "userId",
"exp": "someNumber",
"jti": "randomBytes",
...otherClaims,
"pld": {
...otherUserContent
}
}
String
regular JWT token. Its payload looks like this:
{
"t": "Authomatic-RT",
"iss": "Authomatic",
"aud": ["Authomatic"]
"uid": "userId",
"exp": "someNumber",
"jti": "randomBytes",
"accessTokenJTI": "randomBytes"
}
Object
Token pairs
Object
Verify options to be used when verifying tokens
Object
The allowed user options to for signing tokens
StandardError
The refresh token was not found.
StandardError
The tokens provided do not match
StandardError
The provided input is not a valid token.
Promise.<Tokens>
Returns access and refresh tokens
Kind: global variable
Throws:
TypeError
typeError if any param was not sent exactly as specifiedParam | Type | Description |
---|---|---|
userId | String | |
secret | Secret | |
[content] | Object | user defined properties |
[prolong] | Boolean | if true, the refreshToken will last 4 days and accessToken 1 hour, otherwise the refresh token will last 25 minutes and the accessToken 15 minutes. |
[signOptions] | SignOptions | Options to be passed to jwt.sign |
String
Verifies token, might throw jwt.verify errors
Kind: global variable
Returns: String
- decoded token
Throws:
InvalidToken
invalidTokenTypeError
typeError if any param was not sent exactly as specifiedParam | Type | Description |
---|---|---|
token | String | |
secret | Secret | |
[verifyOptions] | VerifyOptions | Options to pass to jwt.verify. |
Promise.<Tokens>
Issues a new access token using a refresh token and an old token (can be expired).
Kind: global variable
Throws:
RefreshTokenNotFound
refreshTokenNotFoundTokensMismatch
tokensMismatchTypeError
typeError if any param was not sent exactly as specifiedParam | Type | Description |
---|---|---|
refreshToken | String | |
accessToken | String | |
secret | Secret | |
signOptions | SignOptions | Options passed to jwt.sign, ignoreExpiration will be set to true |
Promise.<Boolean>
Invalidates refresh token
Kind: global variable
Returns: Promise.<Boolean>
- true if successful, false otherwise.
Throws:
TypeError
typeError if any param was not sent exactly as specifiedInvalidToken
invalidTokenParam | Type |
---|---|
refreshToken | String |
Promise.<Boolean>
Invalidates all refresh tokens
Kind: global variable
Returns: Promise.<Boolean>
- true if successful, false otherwise.
Throws:
TypeError
typeError if any param was not sent exactly as specifiedParam | Type |
---|---|
userId | String |
String
a string greater than 20 characters
String
Regular JWT token. Its payload looks like this:
{
"t": "Authomatic-AT",
"uid": "userId",
"exp": "someNumber",
"jti": "randomBytes",
...otherClaims,
"pld": {
...otherUserContent
}
}
String
regular JWT token. Its payload looks like this:
{
"t": "Authomatic-RT",
"iss": "Authomatic",
"aud": ["Authomatic"]
"uid": "userId",
"exp": "someNumber",
"jti": "randomBytes",
"accessTokenJTI": "randomBytes"
}
Object
Token pairs
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
accessToken | AccessToken | |
accessTokenExpiresAt | Number | epoch |
refreshToken | RefreshToken | |
refreshTokenExpiresAt | Number | epoch |
Object
Verify options to be used when verifying tokens
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[audience] | Array | String | checks the aud field |
[issuer] | String | Array | checks the iss field |
[ignoreExpiration] | Boolean | if true, ignores the expiration check of access tokens |
[ignoreNotBefore] | Boolean | if true, ignores the not before check of access tokens |
[subject] | String | checks the sub field |
[clockTolerance] | Number | String | |
[maxAge] | String | Number | |
[clockTimestamp] | Number | overrides the clock for the verification process |
Object
The allowed user options to for signing tokens
Kind: global typedef
Properties
Name | Type |
---|---|
[nbf] | Number |
[aud] | Array | String |
[iss] | String |
[sub] | String |
StandardError
The refresh token was not found.
Kind: global typedef
Properties
Name | Type | Default |
---|---|---|
[name] | String | 'RefreshTokenNotFound' |
StandardError
The tokens provided do not match
Kind: global typedef
Properties
Name | Type | Default |
---|---|---|
[name] | String | 'TokensMismatch' |
StandardError
The provided input is not a valid token.
Kind: global typedef
Properties
Name | Type | Default |
---|---|---|
[name] | String | 'InvalidToken' |
If you want to create a new store you need to expose the following functions:
/**
* Register token and refresh token to the user
* @param {String} userId
* @param {String} refreshTokenJTI
* @param {String} accessTokenJTI
* @param {Number} ttl time to live in ms
* @returns {Promise<Boolean>} returns true when created.
*/
function add(userId, refreshTokenJTI, accessTokenJTI, ttl){...}
/**
* Remove a single refresh token from the user
* @param userId
* @param refreshTokenJTI
* @returns {Promise<Boolean>} true if found and deleted, otherwise false.
*/
function remove(userId, refreshTokenJTI) {...}
/**
* Removes all tokens for a particular user
* @param userId
* @returns {Promise<Boolean>} true if any were found and delete, false otherwise
*/
function removeAll(userId) {...}
You may need to expose a reference to the store if the user may need to handle connections during testing for example.
FAQs
An authentication library that uses JWT for access and refresh tokens with sensible defaults.
The npm package authomatic receives a total of 3 weekly downloads. As such, authomatic popularity was classified as not popular.
We found that authomatic demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.