LLMProxy.Provider.TokenCodec behaviour (llm_proxy v0.2.0)

Copy Markdown View Source

Configurable encoding boundary for provider API keys and OAuth tokens.

A codec receives the credential field as context. This lets a codec bind its ciphertext to the field and prevents an access token from being used as a refresh token. Configure a module or a {module, options} tuple with :provider_token_codec.

Summary

Types

context()

@type context() :: %{field: :token | :refresh_token}

options()

@type options() :: keyword() | map()

Callbacks

decode(t, context, options)

@callback decode(String.t(), context(), options()) :: {:ok, String.t()} | {:error, term()}

encode(t, context, options)

@callback encode(String.t(), context(), options()) :: {:ok, String.t()} | {:error, term()}

encoded?(t, options)

@callback encoded?(String.t(), options()) :: boolean()

validate_options(options)

(optional)
@callback validate_options(options()) :: :ok | {:error, term()}

Functions

credential(stored)

@spec credential(LLMProxy.Schemas.ProviderToken.t()) ::
  {:ok, LLMProxy.Provider.Credential.t()} | {:error, term()}

decode(value, field)

@spec decode(String.t() | nil, :token | :refresh_token) ::
  {:ok, String.t() | nil} | {:error, term()}

encode(value, field)

@spec encode(String.t() | nil, :token | :refresh_token) ::
  {:ok, String.t() | nil} | {:error, term()}

encode_attrs(attrs)

@spec encode_attrs(map()) :: {:ok, map()} | {:error, term()}

encoded?(value)

@spec encoded?(String.t() | nil) :: boolean()