Skip to main content

Auths

Auths ⇐ APIClient

Use Fonoster Auth, a capability of Fonoster, to validate and create short life tokens.

Kind: global class
Extends: APIClient
See: module:core:APIClient

new Auths(options)

Constructs a new Auth object.

ParamTypeDescription
optionsClientOptionsOptions to indicate the objects endpoint

Example

const request = {
accessKeyId: "US618572e3ec11d10600000001",
roleName: "USER"
};

auth.createToken(request)
.then(console.log) // returns an object with the token
.catch(console.error); // an error occurred

auths.createToken(request) ⇒ Promise.<CreateTokenResponse>

Creates a short-life token. The client must have role allowed to create tokens.

Kind: instance method of Auths

ParamTypeDescription
requestCreateTokenRequestRequest to create a new token
request.accessKeyIdstringPath to the function
request.expirationstringLongevity of the token
request.roleNamestringRole assigned to the token

Example

const Fonoster = require("@fonoster/sdk");
const auth = new Fonoster.Auth();

const request = {
accessKeyId: "PJ618572e3ec11d10600000001",
roleName: "SERVICE",
expiration: "10m"
};

auth.createToken(request)
.then(console.log) // returns an object with the token
.catch(console.error); // an error occurred

auths.createNoAccessToken(request) ⇒ Promise.<CreateTokenResponse>

Creates a short-life token meant only to serve as a signature. This token will only be useful to sign a request.

Kind: instance method of Auths

ParamTypeDescription
requestCreateTokenRequestRequest to create a new signature token
request.accessKeyIdstringPath to the function

Example

const Fonoster = require("@fonoster/sdk");
const auth = new Fonoster.Auth();

const request = {
accessKeyId: "PJ619154d081467a0700000001",
};

auth.createNoAccessToken(request)
.then(console.log) // returns an object with the token
.catch(console.error); // an error occurred

auths.validateToken(request) ⇒ Promise.<boolean>

Checks if a give token was issue by the system.

Kind: instance method of Auths

ParamTypeDescription
requestCreateTokValidateTokenRequestenRequestRequest to verify the validity of a token
request.tokenstringPath to the function.

Example

const Fonoster = require("@fonoster/sdk");
const auth = new Fonoster.Auth();

const request = {
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
};

auth.validateToken(request)
.then(console.log) // returns `true` or `false`
.catch(console.error); // an error occurred