Reusable OAuth API router for Phoenix applications.
This module provides a complete OAuth API that can be mounted in Phoenix
applications using the forward macro. It handles all OAuth operations
including session creation, authorization URL generation, token exchange,
and connection management.
Usage
In your Phoenix router:
defmodule MyAppWeb.Router do
use MyAppWeb, :router
scope "/api/oauth" do
pipe_through :api
forward "/", Tango.API.Router
end
endConfiguration
The API expects tenant ID to be provided via:
- Request header:
X-Tenant-ID - Connection assigns:
conn.assigns.current_tenant_id
Configure CORS if needed:
config :tango, :api,
cors_origins: ["http://localhost:3000", "https://myapp.com"]Routes
POST /sessions- Create OAuth sessionGET /authorize/:session_token- Get authorization URLPOST /exchange- Exchange authorization code for connectionGET /callback- OAuth callback page for popup flowsGET /health- Health check
Summary
Functions
Callback implementation for Plug.call/2.
Callback implementation for Plug.init/1.