0.2.33 • Published 4 years ago

@appbuckets/server-builder v0.2.33

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

AppBuckets - ServerBuilder

Description

This Module contains all the essentials Functions to create a responsive ServerBuilder
which manage the queues and protect any APIs queries with an authentication Token.


TokenManager()

This Class is a Token Manager. It is called with a secret parameter, and an options Object, which consinst of some settings for creating and managing the Token.

constructor(secretKey, options)

This is the constructor of the Class. You must pass a secret string and an Object which contains all the options you want to use to create your new Token.

Params

  • secretKey
    • type: String
    • description: The string the constructor use to generate the Token
  • options
    • type: Object
    • description: The options Object contains all the settings to create the new Token
    • expiresIn
      • type: String/Number
      • description: The default expire property. This is a string in a time format, like '15m' or '1 year'.
      • default: 15m
    • tokeSize
      • type: Number
      • description: Set the generated token size in bit
      • default: 128
    • tokenProp
      • type: String
      • description: Set the token property name that will be appended to paylod, and will be used to save the generated Token
      • default: token
    • appendRaw
      • type: Boolean
      • description: Set if must append raw generated token to payload
      • default: true
    • clockTollerance
      • type: String
      • description: Set the clock tollerance to evaluate expire date
      • default: 1m
    • issuer
      • type: String
      • description: Set the Token issuer, defining the host is sending and creating the token
      • default: localhost
    • audience
      • type: String
      • description: Set the Token audience, defining who is the receiver of the Token
      • default: client

generate(payload, options)

This Method generate a new Token, using provided payload Object and options Object.
If you want to use an already generated Token you can pass token parameter in options.

Params

  • payload
    • type: Object
    • description: Provided Payload Objects
  • options
    • type: Object
    • description: Options Object, which is similar to the constructor options object
    • default: TokenGenerationOptions
    • expiresIn
      • type: String
      • description: How long the Token is valid. If in the constructor is passed as a Number, a function will convert it into a String.
      • default: this.expiresIn
    • token
      • type: String
      • description: The token to use, if is not passed it will be autogenerated.
    • issuer
      • type: String
      • description: Issuer replacer
      • default: this.issuer
    • audience
      • type: String
      • description: Audience replacer
      • default: this.audience
    • expireAt
      • type: Number
      • description: If it is passed it will overwrite expiresIn param. This must be a date/time to calculate expiresIn

decode(token)

Return a new Token class that build a new JsonWebToken object starting from an encoded token

Params

  • token
    • type: String
    • description: The econdedToken the Function take from
    • default: varDefault

Token()

In this Class there are some Methods to check and use the Token generated. It requires as parameters the encodedToken and an options Object.

constructor(encodedToken, options)

The constructor is called with the ecodedToken to use, and some options to manage, that are the same of tokenManagerOptions by default.

Params

  • encodedToken
    • type: String
    • description: The encoded Token to use
  • options
    • type: Object
    • description:
    • default: tokenManagerOptions

valid()

This is a Property of the Token Class that return 'true' if the Token is valid.

expired()

This is a Property of the Token Class that return true if the the Token is expired.

encoded()

This is a Property of the Token Class that return a String which represents the encoded Token.

toString()

This is a Method of the Token Class that return a String which represents the decoded Token.


toObject()

This Method of the Token Class transform token into a plain Object, and return that Object.