Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Tokens

Tokens is an API module for managing Cafe access tokens

Tokens allow other peers to register with a Cafe peer. Use this API to create, list, validate, and remove tokens required for access to this Cafe.

extends

API

Hierarchy

  • API
    • Tokens

Index

Constructors

Methods

Constructors

constructor

Methods

add

  • add(token?: undefined | string, store?: undefined | false | true): Promise<string>
  • Creates an access token

    Generates an access token (44 random bytes) and saves a bcrypt hashed version for future lookup. The response contains a base58 encoded version of the random bytes token. If the ‘store’ option is set to false, the token is generated, but not stored in the local Cafe db. Alternatively, an existing token can be added using by specifying the ‘token’ option.

    see

    Cafes#add

    Parameters

    • Optional token: undefined | string

      Use an existing token, rather than creating a new one

    • Optional store: undefined | false | true

      Whether to store the added/generated token to the local db (defaults to true)

    Returns Promise<string>

    New token as string

list

  • list(): Promise<string[]>
  • Retrieves information about all stored cafe tokens

    Only really useful for debugging. These are hashed tokens, so are not valid.

    Returns Promise<string[]>

    Array of bcrypt hashed tokens

remove

  • remove(token: string): Promise<boolean>
  • Removes an existing cafe token

    Parameters

    • token: string

      Access token

    Returns Promise<boolean>

    Whether remove was successful

validate

  • validate(token: string): Promise<boolean>
  • Check validity of existing cafe access token

    Parameters

    • token: string

      Access token

    Returns Promise<boolean>

    Whether token is valid