Noizu.Google.OAuth (Noizu Google v0.2.3)

Copy Markdown View Source

OAuth2 helpers for Google APIs.

Authorization URL

Noizu.Google.OAuth.authorize_url(
  client_id: "CLIENT_ID",
  redirect_uri: "https://example.com/oauth/callback",
  scope: "https://www.googleapis.com/auth/webmasters.readonly",
  access_type: "offline",
  prompt: "consent"
)

Exchange code

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

Refresh

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

Summary

Functions

Build the user authorization URL.

Refresh an 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.Google.Error.t()}

Build the user authorization URL.

Options

  • :client_id (required unless on client)
  • :redirect_uri
  • :response_type — default "code"
  • :scope — space-separated scopes
  • :state
  • :access_type"offline" for refresh tokens
  • :prompt — e.g. "consent"
  • :include_granted_scopes
  • :login_hint
  • :code_challenge / :code_challenge_method — PKCE

refresh_token(refresh_token, opts \\ [])

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

Refresh an access token.

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

token(opts \\ [])

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

Exchange an authorization code for tokens.

Options

  • :code (required)
  • :redirect_uri (required for web apps)
  • :client / :client_id / :client_secret
  • :code_verifier — PKCE