Beamlet.Token (Beamlet v0.1.1)

Copy Markdown View Source

The credential one client uses to reach your beamlet.

A token is one of two kinds:

  • cli - Named, and created with beamlet tokens.create or Beamlet.Tokens.create/1. It never expires and lasts until you delete it.
  • oauth - Created when a chat client connects and you consent. It is known by the client's URL, and it expires and refreshes as Beamlet.OAuth describes.

Each token has a policy, default unless another was named.

The secret is set only on the struct that creating the token returns. The beamlet keeps just a hash, so secret is nil on every token loaded afterwards, and a lost secret means a new token.

label/1 is the name the beamlet shows for a token: a cli token's name, or an oauth token's client host.

Summary

Types

A token's kind: cli, minted from the command line, or oauth, minted at consent.

t()

A token as stored.

Functions

Changeset for creating or updating a cli token.

The display form of a token: a cli token's name, or the host of an oauth token's client id.

Changeset for creating an oauth token.

Changeset for refreshing an oauth token.

Types

kind()

@type kind() :: :cli | :oauth

A token's kind: cli, minted from the command line, or oauth, minted at consent.

t()

@type t() :: %Beamlet.Token{
  __meta__: term(),
  client: String.t() | nil,
  expires_at: DateTime.t() | nil,
  id: pos_integer() | nil,
  inserted_at: NaiveDateTime.t() | nil,
  kind: kind(),
  name: String.t() | nil,
  policy: String.t(),
  refresh_expires_at: DateTime.t() | nil,
  refresh_hash: binary() | nil,
  refresh_secret: String.t() | nil,
  secret: String.t() | nil,
  secret_hash: binary() | nil,
  updated_at: NaiveDateTime.t() | nil
}

A token as stored.

The secrets are set only on the struct Beamlet.Tokens.create/1 returns.

Functions

cli_changeset(token, attrs)

@spec cli_changeset(t(), map()) :: Ecto.Changeset.t()

Changeset for creating or updating a cli token.

It casts the name and policy. The name must be unique on the beamlet and the policy one it declares. The hash is set by Beamlet.Tokens, never cast.

label(token)

@spec label(t()) :: String.t()

The display form of a token: a cli token's name, or the host of an oauth token's client id.

oauth_changeset(token, attrs)

@spec oauth_changeset(t(), map()) :: Ecto.Changeset.t()

Changeset for creating an oauth token.

It casts the client id, the policy chosen at consent and both expiries. The hashes are set by Beamlet.Tokens, never cast.

rotate_changeset(token, attrs)

@spec rotate_changeset(t(), map()) :: Ecto.Changeset.t()

Changeset for refreshing an oauth token.

It casts both expiries. The client and policy stay as consented, and the hashes are set by Beamlet.Tokens.