StarlingBank.OAuth (StarlingBank v1.0.0)

Copy Markdown View Source

OAuth2 authorization code flow helpers — exchanging an authorization code for an access/refresh token, and refreshing an expired access token.

Starling's OAuth token endpoint lives on the API host, so this reuses the same zero-dependency transport as the rest of the client, but posts application/x-www-form-urlencoded per the OAuth2 spec instead of JSON.

Authorization URL

Direct the account holder to the URL built by authorize_url/1:

https://oauth.starlingbank.com/?client_id=...&redirect_uri=...&response_type=code&scope=...

(sandbox: https://oauth-sandbox.starlingbank.com/)

Summary

Functions

Builds the authorization-page URL the account holder should be redirected to.

Exchanges an authorization code for an access token + refresh token.

Exchanges a refresh token for a new access token (and rotated refresh token).

Functions

authorize_url(opts)

@spec authorize_url(keyword()) :: String.t()

Builds the authorization-page URL the account holder should be redirected to.

exchange_code(opts)

@spec exchange_code(keyword()) :: {:ok, map()} | {:error, StarlingBank.Error.t()}

Exchanges an authorization code for an access token + refresh token.

StarlingBank.OAuth.exchange_code(
  code: code,
  client_id: client_id,
  client_secret: client_secret,
  redirect_uri: redirect_uri,
  environment: :production
)

refresh_token(opts)

@spec refresh_token(keyword()) :: {:ok, map()} | {:error, StarlingBank.Error.t()}

Exchanges a refresh token for a new access token (and rotated refresh token).