api/utils/authorizer

Module providing one time authentication

Source:

Methods

(static) check_if_expired(options)

Source:

Checks if token is not expired yet

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

token string

token to rvalidate

callback function

function called when reading was completed or errored, providing error object as first param, true or false if expired as second, seconds till expiration as third.(-1 if never expires, 0 - if expired)

(static) clean(options)

Source:

Clean all expired tokens

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

callback function

function called when cleaning completed

(static) extend_token(options)

Source:

extent token life spas

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

token string

token to extend

extendBy string

extend token by given time(in ms)(optional) You have to provide extedBy or extendTill. extendBy==0 makes it never die

extendTill string

extend till given timestamp. (optional) You have to provide extedBy or extendTill

callback function

function called when reading was completed or errored, providing error object as first param and true as second if extending successful

(static) getToken() → {string}

Source:

Generates auhtentication ID

Returns:

id to be used when saving the task

Type
string

(static) read(options)

Source:

Get whole token information from database

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

token string

token to read

callback function

function called when reading was completed or errored, providing error object as first param and token object from database as second

(static) save(options)

Source:

Store token for later authentication

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Attributes Default Description
db object

database connection

ttl number

amount of seconds for token to work, 0 works indefinately

multi bool <optional>
false

if true, can be used many times until expired

token string

token to store, if not provided, will be generated

owner string

id of the user who created this token

app string

list of the apps for which token was created

endpoint string

regexp of endpoint(any string - is used as substring,to mach exact ^{yourpath}$)

tryReuse string

if true - tries to find not expired token with same parameters. If not founds cretes new token. If found - updates token expiration time to new one and returns token.

temporary bool <optional>
false

If logged in with temporary token. Doesn't kill other sessions on logout.

callback function

function called when saving was completed or errored, providing error object as first param and token string as second

(static) verify(options)

Source:

Verify token and expire it

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

token string

token to verify

qstring string

params.qstring. If not passed and there is limitation for this token on params - token will not be valid

req_path string

current request path

callback function

function called when verifying was completed, providing 1 argument, true if could verify token and false if couldn't

(static) verify_return(options)

Source:

Similar to authorizer.verify. Only difference - return token owner if valid.

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

token string

token to verify

qstring string

params.qstring. If not passed and there is limitation for this token on params - token will not be valid

req_path string

current request path

callback function

function called when verifying was completed, providing 1 argument, true if could verify token and false if couldn't

(inner) verify_token(options, return_owner, return_data)

Source:

Token validation function called from verify and verify return

Parameters:
Name Type Description
options object

options for the task

Properties
Name Type Description
db object

database connection

token string

token to validate

qstring string

params.qstring. If not passed and there is limitation for this token on params - token will not be valid

callback function

function called when verifying was completed or errored, providing error object as first param and true as second if extending successful

return_owner boolean

states if in callback owner shold be returned. If return_owner==false, returns true or false.

return_data boolean

states if in callback all token data should be returned.