OAuth authentication helpers for Aurinko.
Aurinko supports three OAuth flows:
- Account Flow — User-delegated authorization producing an account + access token.
- Service Account Flow — Admin/Org-level authorization.
- User Session Flow — Produces an Aurinko User, primary account, and session token.
Account Flow Example
# Step 1: Redirect user to authorization URL
url = Aurinko.Auth.authorize_url(
service_type: "Google",
scopes: ["Mail.Read", "Mail.Send", "Calendars.ReadWrite"],
return_url: "https://yourapp.com/auth/callback",
response_type: "code"
)
# Step 2: Exchange the code for a token
{:ok, token_info} = Aurinko.Auth.exchange_code(code)
# Use token_info.token for subsequent API calls
Summary
Functions
Builds the Aurinko OAuth authorization URL.
Exchanges an authorization code for an Aurinko account access token.
Refreshes an expired Aurinko access token.
Types
Functions
Builds the Aurinko OAuth authorization URL.
Options
:service_type— Provider to authorize (e.g."Google","Office365"). Required.:scopes— List of permission scopes. Defaults to["Mail.Read"].:return_url— Callback URL after authorization. Required.:response_type—"code"(default) or"token".:login_hint— Pre-fill the user's email address.:state— Optional opaque state value for CSRF protection.
Examples
iex> Aurinko.Auth.authorize_url(
...> service_type: "Google",
...> scopes: ["Mail.Read", "Calendars.ReadWrite"],
...> return_url: "https://myapp.com/callback"
...> )
"https://api.aurinko.io/v1/auth/authorize?..."
@spec exchange_code( String.t(), keyword() ) :: {:ok, token_info()} | {:error, Aurinko.Error.t()}
Exchanges an authorization code for an Aurinko account access token.
Examples
{:ok, %{token: token, account_id: id}} = Aurinko.Auth.exchange_code("auth_code_here")
@spec refresh_token( String.t(), keyword() ) :: {:ok, token_info()} | {:error, Aurinko.Error.t()}
Refreshes an expired Aurinko access token.