Tango.API.Router (tango v0.1.2)

Copy Markdown View Source

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
end

Configuration

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 session
  • GET /authorize/:session_token - Get authorization URL
  • POST /exchange - Exchange authorization code for connection
  • GET /callback - OAuth callback page for popup flows
  • GET /health - Health check

Summary

Functions

Callback implementation for Plug.call/2.

Callback implementation for Plug.init/1.

Functions

call(conn, opts)

Callback implementation for Plug.call/2.

init(opts)

Callback implementation for Plug.init/1.