generateToken (src/token.ts)

platform · foundations/core/packages/token/src/token.ts · typescript · EPL-2.0
auth, tag:embed-classified

Utility for generating, decoding, and validating JWT tokens with revocation support.

// Source: https://github.com/hcengineering/platform | License: EPL-2.0 | Modified files must remain under EPL-2.0
// Modifications to this file must remain under EPL-2.0.
// Provided via justclaw.it.com; keep this notice with the code.
import { AccountRole, AccountUuid, MeasureContext, PersonUuid, WorkspaceUuid } from '@hcengineering/core'
import { getMetadata } from '@hcengineering/platform'
import { decode, encode } from 'jwt-simple'
import { validate } from 'uuid'
import serverPlugin from './plugin'

/**
 * @public
 */
export interface Token {
  account: AccountUuid
  workspace: WorkspaceUuid
  extra?: Record<string, any>
  grant?: PermissionsGrant

  sub?: AccountUuid // Subject
  exp?: number // Expiration, seconds since epoch
  nbf?: number // Not valid before, seconds since epoch
}

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key