Sptfy.OAuth (Sptfy v0.1.3) View Source

This provides functions to obtain authorization with authorization code flow.

https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow

Link to this section Summary

Functions

Requests access token and refresh token to the Spotify Accounts service.

Exchanges a refresh token for new access token.

Returns a URL to request an authorization code.

Link to this section Types

Specs

response() ::
  {:ok, Sptfy.Object.OAuthResponse.t()}
  | {:error, Sptfy.Object.OAuthError.t()}
  | {:error, Mint.Types.error()}

Link to this section Functions

Link to this function

get_token(client_id, client_secret, code, redirect_uri)

View Source

Specs

get_token(
  client_id :: String.t(),
  client_secret :: String.t(),
  code :: String.t(),
  redirect_uri :: String.t()
) :: response()

Requests access token and refresh token to the Spotify Accounts service.

Link to this function

refresh_token(client_id, client_secret, refresh_token)

View Source

Specs

refresh_token(
  client_id :: String.t(),
  client_secret :: String.t(),
  refresh_token :: String.t()
) :: response()

Exchanges a refresh token for new access token.

Link to this function

url(client_id, redirect_uri, params \\ %{})

View Source

Specs

url(
  client_id :: String.t(),
  redirect_uri :: String.t(),
  params :: map() | Keyword.t()
) :: String.t()

Returns a URL to request an authorization code.

iex> Sptfy.OAuth.url("CLIENT_ID", "https://example.com/callback")
...> "https://accounts.spotify.com/authorize?client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&response_type=code&scope="

iex> Sptfy.OAuth.url("CLIENT_ID", "https://example.com/callback", %{scope: ["streaming"]})
...> "https://accounts.spotify.com/authorize?client_id=CLIENT_ID&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&response_type=code&scope=streaming"