PlaidEx.OAuth.Flow (plaid_ex v1.0.0)

Copy Markdown View Source

High-level OAuth flow orchestration for Plaid Link.

Manages the complete OAuth flow for institutions that require out-of-app authorization (e.g., Chase, Wells Fargo, Capital One).

Flow overview

Desktop / web flow:

  1. initiate/2 — creates Link token with PKCE, stores state
  2. User completes Link, is redirected to your oauth_redirect_uri
  3. complete/2 — validates state, exchanges public token

Example

{:ok, %{link_token: token, oauth_state: state}} =
  PlaidEx.OAuth.Flow.initiate(config,
    user_id: "user-123",
    products: ["transactions"],
    redirect_uri: "https://myapp.com/oauth/callback"
  )

Summary

Functions

Completes an OAuth flow after the user is redirected back.

Initiates an OAuth Link flow.

Types

initiate_opts()

@type initiate_opts() :: [
  user_id: String.t(),
  products: [String.t()],
  country_codes: [String.t()],
  redirect_uri: String.t(),
  language: String.t(),
  tenant_id: String.t() | nil,
  additional_consented_products: [String.t()]
]

initiate_result()

@type initiate_result() :: %{
  link_token: String.t(),
  expiration: String.t(),
  oauth_state: String.t(),
  pkce: PlaidEx.OAuth.PKCE.t()
}

Functions

complete(config, opts)

@spec complete(
  PlaidEx.Config.t(),
  keyword()
) ::
  {:ok, %{access_token: String.t(), item_id: String.t()}}
  | {:error, PlaidEx.Error.t()}

Completes an OAuth flow after the user is redirected back.

Validates state, retrieves PKCE verifier, and exchanges the public token for an access token.

initiate(config, opts)

@spec initiate(PlaidEx.Config.t(), initiate_opts()) ::
  {:ok, initiate_result()} | {:error, PlaidEx.Error.t()}

Initiates an OAuth Link flow.

Creates a Link token with PKCE challenge and stores OAuth state.