Atex.OAuth (atex v0.10.0)

View Source

AT Protocol OAuth 2.0 session management.

Provides Plug session helpers for managing OAuth sessions in a web application. For the full OAuth flow, see Atex.OAuth.Flow. For authorization server discovery, see Atex.OAuth.Discovery. For DPoP token handling, see Atex.OAuth.DPoP.

Type re-exports

The following types are re-exported here for backward compatibility:

Summary

Functions

Generate a random base64url-encoded nonce suitable for use in OAuth flows.

Get the key of the currently active OAuth session from the connection.

Delete the currently active OAuth session.

List all OAuth session keys stored in the connection's session.

Return the session key atom used to store the active session key in a Plug.Conn session.

Return the session key atom used to store the list of session keys in a Plug.Conn session.

Switch the active OAuth session to the given key.

Types

authorization_metadata()

@type authorization_metadata() :: Atex.OAuth.Flow.authorization_metadata()

tokens()

@type tokens() :: Atex.OAuth.Flow.tokens()

Functions

create_nonce()

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

Generate a random base64url-encoded nonce suitable for use in OAuth flows.

Returns a 32-byte random value encoded as a URL-safe base64 string without padding. Useful when building custom authorization flows.

Examples

iex> nonce = Atex.OAuth.create_nonce()
iex> is_binary(nonce)
true

current_session_key(conn)

@spec current_session_key(Plug.Conn.t()) :: String.t() | nil

Get the key of the currently active OAuth session from the connection.

Returns nil if no session is currently active.

Parameters

delete_session(conn)

@spec delete_session(Plug.Conn.t()) :: Plug.Conn.t()

Delete the currently active OAuth session.

Removes the active session from SessionStore, removes its key from the session key list, and clears the active session pointer in the Plug session.

Parameters

list_session_keys(conn)

@spec list_session_keys(Plug.Conn.t()) :: [String.t()]

List all OAuth session keys stored in the connection's session.

Parameters

session_active_session_name()

@spec session_active_session_name() :: atom()

Return the session key atom used to store the active session key in a Plug.Conn session.

Used by Atex.OAuth.Plug when reading and writing session data.

session_keys_name()

@spec session_keys_name() :: atom()

Return the session key atom used to store the list of session keys in a Plug.Conn session.

Used by Atex.OAuth.Plug when reading and writing session data.

switch_session(conn, session_key)

@spec switch_session(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Switch the active OAuth session to the given key.

Updates the :atex_active_session value in the Plug session.

Parameters

  • conn - A Plug.Conn with session data loaded
  • session_key - The session key to make active