Ueberauth TeamSnap v0.1.0 Ueberauth.Strategy.TeamSnap View Source

Provides an Ueberauth strategy for authenticating with TeamSnap.

Setup

Create an application in TeamSnap for you to use.

Register a new application at: TeamSnap Authentication and get the client_id and client_secret.

Include the provider in your configuration for Ueberauth

config :ueberauth, Ueberauth,
  providers: [
    teamsnap: {Ueberauth.Strategy.TeamSnap, []}
  ]

Then include the configuration for TeamSnap.

config :ueberauth, Ueberauth.Strategy.TeamSnap.OAuth,
  client_id: System.get_env("TEAM_SNAP_CLIENT_ID"),
  client_secret: System.get_env("TEAM_SNAP_CLIENT_SECRET")

Configure :oauth2 to serialize Collection+JSON data. If you’re using Poison, your configuartion will look like this:

config :oauth2,
  serializers: %{
    "application/json" => Poison,
    "application/vnd.collection+json" => Poison
  }

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: [
    teamsnap: {Ueberauth.Strategy.TeamSnap, [uid_field: :email]}
  ]

Default is :id

To set the default ‘scopes’ (permissions):

config :ueberauth, Ueberauth,
  providers: [
    teamsnap: {Ueberauth.Strategy.TeamSnap, [default_scope: "read write_members write_teams"]}
  ]

Default is read. To use multiple scopes, pass a space-separated list to the scope parameter.

Link to this section Summary

Functions

Includes the credentials from the TeamSnap response

Stores the raw information (including the token) obtained from the TeamSnap callback

Cleans up the private area of the connection used for passing the raw TeamSnap response around during the callback

Handles the initial redirect to the TeamSnap Authentication page

Fetches the fields to populate the info section of the Ueberauth.Auth struct

Fetches the uid field from the TeamSnap response. This defaults to the option uid_field which in-turn defaults to id

Link to this section Functions

Includes the credentials from the TeamSnap response.

Stores the raw information (including the token) obtained from the TeamSnap callback.

Cleans up the private area of the connection used for passing the raw TeamSnap response around during the callback.

Handles the initial redirect to the TeamSnap Authentication page.

To customize the scope (permissions) that are requested by TeamSnap include them as part of your url:

"/auth/teamsnap?scope=read+write"

Fetches the fields to populate the info section of the Ueberauth.Auth struct.

Fetches the uid field from the TeamSnap response. This defaults to the option uid_field which in-turn defaults to id