Ueberauth StackOverflow v0.0.3 Ueberauth.Strategy.StackOverflow View Source
Provides an Ueberauth strategy for authenticating with StackOverflow.
Setup
Create an application in StackOverflow for you to use.
Register a new application at: StackExchange and get the client_id and client_secret.
Include the provider in your configuration for Ueberauth
config :ueberauth, Ueberauth,
providers: [
stackoverflow: { Ueberauth.Strategy.StackOverflow, [] }
]
Then include the configuration for stackoverflow.
config :ueberauth, Ueberauth.Strategy.StackOverflow.OAuth,
client_id: System.get_env("SO_CLIENT_ID"),
client_secret: System.get_env("SO_CLIENT_SECRET")
If you haven't already, create a pipeline and setup routes for your callback handler
pipeline :auth do
Ueberauth.plug "/auth"
end
scope "/auth" do
pipe_through [:browser, :auth]
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.
To set the uid_field
config :ueberauth, Ueberauth,
providers: [
stackoverflow: { Ueberauth.Strategy.StackOverflow, [uid_field: :email] }
]
Default is :id
To set the default 'scopes' (permissions):
config :ueberauth, Ueberauth,
providers: [
stackoverflow: { Ueberauth.Strategy.StackOverflow, [default_scope: "no_expiry"] }
]
Default is "" (empty)
Link to this section Summary
Functions
Includes the credentials from the StackOverflow response
Stores the raw information (including the token) obtained from the StackOverflow callback
Cleans up the private area of the connection used for passing the raw StackOverflow response around during the callback
Handles the initial redirect to the stackoverflow authentication page
Fetches the fields to populate the info section of the Ueberauth.Auth struct
Fetches the uid field from the StackOverflow response. This defaults to the option account_id
Link to this section Functions
auth(conn) View Source
credentials(conn) View Source
Includes the credentials from the StackOverflow response.
default_options() View Source
extra(conn) View Source
Stores the raw information (including the token) obtained from the StackOverflow callback.
handle_cleanup!(conn) View Source
Cleans up the private area of the connection used for passing the raw StackOverflow response around during the callback.
handle_request!(conn) View Source
Handles the initial redirect to the stackoverflow authentication page.
To customize the scope (permissions) that are requested by stackoverflow include them as part of your url:
"/auth/stackoverflow?scope=no_expiry,private_info"
You can also include a state param that stackoverflow will return to you.
info(conn) View Source
Fetches the fields to populate the info section of the Ueberauth.Auth struct.
uid(conn) View Source
Fetches the uid field from the StackOverflow response. This defaults to the option account_id