Amur.Controller (amur v0.3.4)

Copy Markdown

Coordinates the provider-facing part of Amur's OAuth flow.

request/2 resolves a configured provider, builds its authorization URL, stores the provider-specific session parameters, and redirects the user to the provider. callback/2 consumes that session state, exchanges the callback parameters for a token, normalizes the provider's user response, and invokes the configured :on_success callback.

Both entry points use the configured :on_failure callback when a provider cannot be resolved, an OAuth operation fails, or the callback session state is invalid. The default failure handler redirects to /.

The controller expects the surrounding Plug pipeline to fetch the session before calling these functions. Amur.Router performs that setup automatically.

Summary

Functions

Completes an OAuth authorization request for the provider in params.

Handles an OAuth failure when no custom :on_failure callback is configured.

Starts an OAuth authorization request for the provider in params.

Functions

callback(conn, params)

Completes an OAuth authorization request for the provider in params.

The callback consumes and immediately removes the session parameters saved by request/2, validates that they contain a non-empty state, and passes them with the callback parameters to the provider strategy. On success, the provider user is normalized and sent to the configured :on_success callback together with the token.

Returns the connection returned by the success or failure callback.

default_failure(conn, reason)

Handles an OAuth failure when no custom :on_failure callback is configured.

The default behavior redirects the user to the application root.

request(conn, map)

Starts an OAuth authorization request for the provider in params.

The provider's strategy supplies the authorization URL and any parameters that must survive until the callback, such as the OAuth state value. Those parameters are stored in the Plug session before the redirect.

Returns a halted connection after redirecting to the provider, or the connection returned by the configured failure callback.