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
@type authorization_metadata() :: Atex.OAuth.Flow.authorization_metadata()
@type tokens() :: Atex.OAuth.Flow.tokens()
Functions
@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
@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
conn- APlug.Connwith session data loaded
@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
conn- APlug.Connwith session data loaded
@spec list_session_keys(Plug.Conn.t()) :: [String.t()]
List all OAuth session keys stored in the connection's session.
Parameters
conn- APlug.Connwith session data loaded
@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.
@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.
@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- APlug.Connwith session data loadedsession_key- The session key to make active