barrel_mcp_client_auth behaviour (barrel_mcp v2.0.2)

View Source

Authorization behaviour for barrel_mcp_client.

The HTTP transport calls into this module to obtain the bearer token to attach to outgoing requests, and to refresh the token when the server returns 401.

A handle is an opaque term passed back into every callback. Static bearer tokens use barrel_mcp_client_auth_bearer; OAuth 2.1 with PKCE will use barrel_mcp_client_auth_oauth (Phase D).

Summary

Functions

Lookup the Authorization header for the current state.

Construct an auth handle from a user-facing config term.

Refresh after a 401, returning a new handle.

Types

handle/0

-type handle() :: term().

t/0

-type t() :: {module(), handle()} | none.

Callbacks

header/1

-callback header(handle()) -> {ok, binary()} | none | {error, term()}.

init/1

-callback init(Config :: term()) -> {ok, handle()} | {error, term()}.

refresh/2

-callback refresh(handle(), WwwAuthenticate :: binary() | undefined) -> {ok, handle()} | {error, term()}.

Functions

header(_)

-spec header(t()) -> {ok, binary()} | none | {error, term()}.

Lookup the Authorization header for the current state.

new(_)

-spec new(none |
          {bearer, binary()} |
          {oauth, map()} |
          {oauth_client_credentials, map()} |
          {oauth_enterprise, map()}) ->
             t() | {error, term()}.

Construct an auth handle from a user-facing config term.

refresh(_, Www)

-spec refresh(t(), binary() | undefined) -> {ok, t()} | {error, term()}.

Refresh after a 401, returning a new handle.