ExDisco.Auth.Authorization (ex_disco v0.1.0)

Copy Markdown View Source

The single public-facing authentication type for the Discogs API.

Use the factory functions to create an Authorization and pass it as the first argument to any function that requires authentication.

Personal Token

token = ExDisco.Config.user_token()
auth = ExDisco.Auth.Authorization.for_user_token(token)

auth
|> ExDisco.Users.get_identity()

OAuth

{:ok, credentials} = ExDisco.Auth.access_token(request_token, verifier)

credentials
|> ExDisco.Users.get_identity()

Summary

Functions

Creates an Authorization from OAuth credentials.

Creates an Authorization from a personal token string.

Types

t()

@type t() :: %ExDisco.Auth.Authorization{
  credentials: term(),
  type: :user_token | :oauth
}

Functions

for_oauth(consumer_key, consumer_secret, token, token_secret)

@spec for_oauth(String.t(), String.t(), String.t(), String.t()) :: t()

Creates an Authorization from OAuth credentials.

Examples

iex> ExDisco.Auth.Authorization.for_oauth("key", "secret", "token", "token_secret")
%ExDisco.Auth.Authorization{type: :oauth, credentials: %{...}}

for_user_token(token)

@spec for_user_token(String.t()) :: t()

Creates an Authorization from a personal token string.

Examples

iex> ExDisco.Auth.Authorization.for_user_token("my_token")
%ExDisco.Auth.Authorization{type: :user_token, credentials: "my_token"}