Atex.XRPC.OAuthClient (atex v0.6.0)

View Source

Summary

Functions

Create an OAuthClient struct from a Plug.Conn.

Ask the client's OAuth server for a new set of auth tokens.

Updates a Plug.Conn session with the latest values from the client.

Types

t()

@type t() :: %Atex.XRPC.OAuthClient{
  access_token: String.t(),
  did: String.t(),
  dpop_key: JOSE.JWK.t(),
  dpop_nonce: (String.t() | nil) | nil,
  endpoint: String.t(),
  expires_at: NaiveDateTime.t(),
  issuer: String.t(),
  refresh_token: String.t()
}

Functions

from_conn(conn)

@spec from_conn(Plug.Conn.t()) :: {:ok, t()} | :error

Create an OAuthClient struct from a Plug.Conn.

Requires the conn to have passed through Plug.Session and Plug.Conn.fetch_session/2 so that the session can be acquired and have the atex_oauth key fetched from it.

Returns :error if the state is missing or is not the expected shape.

get(client, resource, opts \\ [])

See Atex.XRPC.get/3.

new(endpoint, did, access_token, refresh_token, expires_at, dpop_key, dpop_nonce)

@spec new(
  String.t(),
  String.t(),
  String.t(),
  String.t(),
  NaiveDateTime.t(),
  JOSE.JWK.t(),
  String.t() | nil
) :: t()

Create a new OAuthClient struct.

post(client, resource, opts \\ [])

See Atex.XRPC.post/3.

refresh(client)

@spec refresh(t()) :: {:ok, t()} | {:error, any()}

Ask the client's OAuth server for a new set of auth tokens.

You shouldn't need to call this manually for the most part, the client does it's best to refresh automatically when it needs to.

update_plug(conn, client)

@spec update_plug(Plug.Conn.t(), t()) :: Plug.Conn.t()

Updates a Plug.Conn session with the latest values from the client.

Ideally should be called at the end of routes where XRPC calls occur, in case the client has transparently refreshed, so that the user is always up to date.