Noizu.Dropbox.OAuth (Noizu Dropbox v0.1.0)

Copy Markdown View Source

OAuth2 helpers for Dropbox.

Supports the modern short-lived access token + refresh token flow.

Authorization URL

Noizu.Dropbox.OAuth.authorize_url(
  client_id: "APP_KEY",
  redirect_uri: "https://example.com/oauth/callback",
  token_access_type: "offline",
  scope: "files.content.read files.content.write account_info.read"
)

Exchange code

Noizu.Dropbox.OAuth.token(
  code: code,
  redirect_uri: redirect_uri,
  client: client
)

Refresh

Noizu.Dropbox.OAuth.refresh_token(refresh_token, client: client)

Summary

Functions

Build the user authorization URL.

Generate a PKCE code_verifier / S256 code_challenge pair.

Refresh and return an updated %Client{} with the new access token.

Refresh a short-lived access token.

Exchange an authorization code for tokens.

Types

options()

@type options() :: keyword() | map()

Functions

authorize_url(opts \\ [])

@spec authorize_url(options()) :: String.t() | {:error, Noizu.Dropbox.Error.t()}

Build the user authorization URL.

Options

  • :client_id / app key (required unless on client)
  • :redirect_uri
  • :response_type — default "code"
  • :state
  • :token_access_type"offline" to receive a refresh token
  • :scope — space-separated scopes
  • :include_granted_scopes"user" | "team"

  • :code_challenge / :code_challenge_method — PKCE
  • :force_reapprove, :disable_signup, :require_role, :locale

pkce_pair()

@spec pkce_pair() :: %{
  code_verifier: String.t(),
  code_challenge: String.t(),
  method: String.t()
}

Generate a PKCE code_verifier / S256 code_challenge pair.

refresh_client(client)

@spec refresh_client(Noizu.Dropbox.Client.t()) ::
  {:ok, Noizu.Dropbox.Client.t(), map()} | {:error, Noizu.Dropbox.Error.t()}

Refresh and return an updated %Client{} with the new access token.

refresh_token(refresh_token, opts \\ [])

@spec refresh_token(String.t(), options()) ::
  {:ok, map()} | {:error, Noizu.Dropbox.Error.t()}

Refresh a short-lived access token.

token(opts \\ [])

@spec token(options()) :: {:ok, map()} | {:error, Noizu.Dropbox.Error.t()}

Exchange an authorization code for tokens.

Returns a map with string keys such as "access_token", "refresh_token", "expires_in", "token_type", "account_id", "uid", "scope".