View Source TwitchAPI.Auth (hello_twitch_api v0.5.1)

Twitch API Auth (and struct).

Functions for managing your auth and tokens.

See: https://dev.twitch.tv/docs/authentication/getting-tokens-oauth

Notes

  • Implicit grant flow gives user access tokens. Expiry: I don't know yet.

  • Client Credentials grant flow gives app access tokens that expire in 5011271 seconds (~58 days).

  • Authorization Code grant flow gives user access tokens that expires in 14124 seconds (~4 hours).

  • Device Code grant flow gives a user access token that expires in 14820 seconds (~4 hours).

Summary

Functions

Merge string params into Auth struct.

Make a new Auth struct with a client_id.

Make a new Auth struct with a client_id and client_secret.

Make a new Auth struct with a client_id, client_secret, and access_token.

Make a new Auth struct with a client_id, client_secret, access_token, and refresh_token.

Add an access_token to the Auth struct.

Add a client_secret to the Auth struct.

Types

@type t() :: %TwitchAPI.Auth{
  access_token: String.t() | nil,
  client_id: String.t(),
  client_secret: String.t() | nil,
  expires_at: DateTime.t() | nil,
  refresh_token: String.t() | nil
}

Functions

Link to this function

merge_string_params(auth, params)

View Source
@spec merge_string_params(t(), params :: %{required(String.t()) => term()}) :: t()

Merge string params into Auth struct.

Example

iex> auth = Auth.new("some-client-id")
iex> params = %{"access_token" => "abc123", "refresh_token" => "def456"}
iex> Auth.merge_string_params(auth, params)
%Auth{
  client_id: "some-client-id",
  access_token: "abc123",
  refresh_token: "def456"
}
@spec new(client_id :: String.t()) :: t()

Make a new Auth struct with a client_id.

Example

iex> Auth.new("some-client-id")
%Auth{client_id: "some-client-id"}
Link to this function

new(client_id, client_secret)

View Source
@spec new(client_id :: String.t(), client_secret :: String.t() | nil) :: t()

Make a new Auth struct with a client_id and client_secret.

Example

iex> Auth.new("some-client-id", "secretssss")
%Auth{client_id: "some-client-id", client_secret: "secretssss"}
Link to this function

new(client_id, client_secret, access_token)

View Source
@spec new(
  client_id :: String.t(),
  client_secret :: String.t() | nil,
  access_token :: String.t() | nil
) :: t()

Make a new Auth struct with a client_id, client_secret, and access_token.

Example

iex> Auth.new("some-client-id", "secretssss", "sometokenabc123")
%Auth{client_id: "some-client-id", client_secret: "secretssss", access_token: "sometokenabc123"}
Link to this function

new(client_id, client_secret, access_token, refresh_token)

View Source
@spec new(
  client_id :: String.t(),
  client_secret :: String.t() | nil,
  access_token :: String.t() | nil,
  refresh_token :: String.t() | nil
) :: t()

Make a new Auth struct with a client_id, client_secret, access_token, and refresh_token.

Example

iex> Auth.new("some-client-id", "secretssss", "sometokenabc123", "somerefreshabc123")
%Auth{
  client_id: "some-client-id",
  client_secret: "secretssss",
  access_token: "sometokenabc123",
  refresh_token: "somerefreshabc123"
}
Link to this function

put_access_token(auth, access_token)

View Source
@spec put_access_token(t(), access_token :: String.t() | nil) :: t()

Add an access_token to the Auth struct.

Example

iex> auth = Auth.new("some-client-id")
iex> Auth.put_access_token(auth, "abc123")
%Auth{client_id: "some-client-id", access_token: "abc123"}
Link to this function

put_client_secret(auth, client_secret)

View Source
@spec put_client_secret(t(), client_secret :: String.t() | nil) :: t()

Add a client_secret to the Auth struct.

Example

iex> auth = Auth.new("some-client-id")
iex> Auth.put_client_secret(auth, "secretssss")
%Auth{client_id: "some-client-id", client_secret: "secretssss"}