Lightning.Tokens.CredentialTransferToken (Lightning v2.19.0-pre)

View Source

A short-lived, ownership-bound token for confirming a credential transfer.

The owner, credential and receiver are baked into the signed payload, so they cannot be swapped by editing the confirmation URL. The token is stateless: revocation and single-use are enforced by the credential's transfer_status (a cancelled or completed transfer fails the pending and ownership guards in Lightning.Credentials.confirm_transfer/2), not by the token itself.

The sub uses a credential_transfer: prefix rather than user: so these tokens are rejected by Lightning.Tokens.verify/1 and cannot double as API bearer tokens.

Summary

Functions

generate_and_sign(extra_claims \\ %{}, key \\ __default_signer__())

@spec generate_and_sign(Joken.claims(), Joken.signer_arg()) ::
  {:ok, Joken.bearer_token(), Joken.claims()} | {:error, Joken.error_reason()}

Combines generate_claims/1 and encode_and_sign/2

generate_and_sign!(extra_claims \\ %{}, key \\ __default_signer__())

@spec generate_and_sign!(Joken.claims(), Joken.signer_arg()) :: Joken.bearer_token()

Same as generate_and_sign/2 but raises if error

verify_and_validate(bearer_token, key \\ __default_signer__(), context \\ %{})

@spec verify_and_validate(Joken.bearer_token(), Joken.signer_arg(), term()) ::
  {:ok, Joken.claims()} | {:error, Joken.error_reason()}

Combines verify/2 and validate/2

verify_and_validate!(bearer_token, key \\ __default_signer__(), context \\ %{})

@spec verify_and_validate!(Joken.bearer_token(), Joken.signer_arg(), term()) ::
  Joken.claims()

Same as verify_and_validate/2 but raises if error