/adonis-action-token

🎬 Create temporary token to perform specific actions like email validation, password recovery & more possibilities.

Primary LanguageTypeScriptMIT LicenseMIT

🎬 Adonis Action Token

Adonis Action Token create temporary token to perform specific actions like email validation, password recovery & more possibilities.

Works only for Adonis v5.

👷‍♀️ In progress 👷‍♂️


Tests CodeQL


Description

Action token is use to manage access (time-limited) for specific resource defined by action type. They are not intended to be used for authentication purposes.

The token works like opaque token (only string identifier, all useful data are stored directly on redis).

Example

  1. Create action token
// create(type: string, ttl: int, data: string | undefined): string
const actionToken = await ActionToken.create('email-validation', 1800, { email: 'myemail@crbast.ch' })

// actionToken = 1608568833696DtHvtHx2DvxeTiHRLshXwhVvIlb34k8yHor1jKlqV5
  1. Validate token (middleware)
// verify(action: string, token: string): ActionToken
await ActionToken.verify('email-validation', actionToken)
  1. Get token data
// ActionToken(action: string, token: string): ActionToken
const token = new ActionToken('email-validation', token )
const data = token.data
  1. Delete token
// ActionToken(action: string, token: string): ActionToken
const token = new ActionToken('email-validation', token )
await token.delete()

Project example

The project elloow - api use the action token concept (organisation creation with email link).

Installation

Dependencies