View Source TwitchAPI.Auth (hello_twitch_api v0.5.2)
Twitch API Auth (and struct).
Functions for managing your auth and tokens.
See: https://dev.twitch.tv/docs/authentication/getting-tokens-oauth
Notes
Implicitgrant flow gives user access tokens. Expiry: I don't know yet.Client Credentialsgrant flow gives app access tokens that expire in5011271seconds (~58 days).Authorization Codegrant flow gives user access tokens that expires in14124seconds (~4 hours).Device Codegrant flow gives a user access token that expires in14820seconds (~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
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"
}
Make a new Auth struct with a client_id.
Example
iex> Auth.new("some-client-id")
%Auth{client_id: "some-client-id"}
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"}
@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"}
@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"
}
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"}
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"}