OpenFeed.Scopes (OpenFeed v0.1.0)

Copy Markdown View Source

OpenFeed's OAuth scopes, and shorthand atoms for them.

The full scope strings are verbose and easy to typo, so every function that takes scopes accepts either the string or a shorthand atom:

iex> OpenFeed.Scopes.expand([:banking, :energy])
["openid", "offline_access", "openfeed-au:data:banking:read",
 "openfeed-au:data:energy:read"]

openid and offline_access are added automatically unless you opt out — without offline_access you get no refresh token, and a grant you cannot refresh is a grant you have to re-consent every few minutes.

Summary

Functions

Expand a list of shorthand atoms and/or literal scope strings.

The shorthand atom to scope string mapping.

Functions

expand(scopes, opts \\ [])

@spec expand(
  [atom() | String.t()],
  keyword()
) :: [String.t()]

Expand a list of shorthand atoms and/or literal scope strings.

Prepends openid and offline_access unless base: false. Deduplicates while preserving order.

Examples

iex> OpenFeed.Scopes.expand([:banking])
["openid", "offline_access", "openfeed-au:data:banking:read"]

iex> OpenFeed.Scopes.expand([:grant_list], base: false)
["openfeed-au:grant:all:list"]

iex> OpenFeed.Scopes.expand(["custom:scope"], base: false)
["custom:scope"]

shorthands()

@spec shorthands() :: %{required(atom()) => String.t()}

The shorthand atom to scope string mapping.