View Source Ueberauth.Strategy.Twitch (ueberauth_twitch v0.2.0)
Provides an Ueberauth strategy for authenticating with Twitch.
Setup
Create an application in Twitch for you to use.
Register a new application at: your twitch developer page and get the client_id
and client_secret
.
Include the provider in your configuration for Ueberauth
config :ueberauth, Ueberauth,
providers: [
twitch: { Ueberauth.Strategy.Twitch, [] }
]
Then include the configuration for twitch.
config :ueberauth, Ueberauth.Strategy.Twitch.OAuth,
client_id: System.get_env("TWITCH_CLIENT_ID"),
client_secret: System.get_env("TWITCH_CLIENT_SECRET")
If you haven't already, create a pipeline and setup routes for your callback handler
pipeline :browser do
plug Ueberauth
...
end
scope "/auth", MyApp do
pipe_through :browser
get "/:provider", AuthController, :request
get "/:provider/callback", AuthController, :callback
end
Create an endpoint for the callback where you will handle the Ueberauth.Auth
struct
defmodule MyApp.AuthController do
use MyApp.Web, :controller
def callback_phase(%{ assigns: %{ ueberauth_failure: fails } } = conn, _params) do
# do things with the failure
end
def callback_phase(%{ assigns: %{ ueberauth_auth: auth } } = conn, params) do
# do things with the auth
end
end
You can edit the behaviour of the Strategy by including some options when you register your provider.
Default is user:read:email
To set the default 'scopes' (permissions):
config :ueberauth, Ueberauth,
providers: [
twitch: { Ueberauth.Strategy.Twitch, [default_scope: "user:read:email"] }
]
Summary
Functions
Includes the credentials from the Twitch response.
Callback implementation for Ueberauth.Strategy.default_options/0
.
Stores the raw information (including the token) obtained from the Twitch callback.
Cleans up the private area of the connection used for passing the raw Twitch response around during the callback.
Handles the initial redirect to the twitch authentication page.
Fetches the fields to populate the info section of the Ueberauth.Auth
struct.
Fetches the uid field from the Twitch response. This defaults to the option uid_field
which in-turn defaults to id
Functions
Includes the credentials from the Twitch response.
Callback implementation for Ueberauth.Strategy.default_options/0
.
Stores the raw information (including the token) obtained from the Twitch callback.
Cleans up the private area of the connection used for passing the raw Twitch response around during the callback.
Handles the initial redirect to the twitch authentication page.
To customize the scope (permissions) that are requested by twitch include them as part of your url:
"/oauth2/token?scope=api read_user read_registry"
You can also include a state
param that twitch will return to you.
Fetches the fields to populate the info section of the Ueberauth.Auth
struct.
Fetches the uid field from the Twitch response. This defaults to the option uid_field
which in-turn defaults to id