Skip to content
This repository has been archived by the owner on Nov 13, 2020. It is now read-only.

teamsnap/ueberauth_teamsnap

Repository files navigation

Überauth TeamSnap

TeamSnap OAuth2 strategy for Überauth.

Installation

  1. Setup your application at TeamSnap Authentication.

  2. Add :ueberauth_team_snap to your list of dependencies in mix.exs:

    def deps do
      [{:ueberauth_team_snap, "~> 0.1"}]
    end
  3. Add the strategy to your applications:

    def application do
      [applications: [:ueberauth_team_snap]]
    end
  4. Add TeamSnap to your Überauth configuration:

    config :ueberauth, Ueberauth,
      providers: [
        teamsnap: {Ueberauth.Strategy.TeamSnap, []}
      ]
  5. Update your provider configuration:

    config :ueberauth, Ueberauth.Strategy.TeamSnap.OAuth,
      client_id: System.get_env("TEAM_SNAP_CLIENT_ID"),
      client_secret: System.get_env("TEAM_SNAP_CLIENT_SECRET")
  6. Configure :oauth2 to serialize application/vnd.collection+json content types:

    config :oauth2,
      serializers: %{
        "application/json" => Poison,
        "application/vnd.collection+json" => Poison
      }
  7. Include the Überauth plug in your controller:

    defmodule MyApp.AuthController do
      use MyApp.Web, :controller
    
      pipeline :browser do
        plug Ueberauth
        ...
       end
    end
  8. Create the request and callback routes if you haven't already:

    scope "/auth", MyApp do
      pipe_through :browser
    
      get "/:provider", AuthController, :request
      get "/:provider/callback", AuthController, :callback
    end
  9. Your controller needs to implement callbacks to deal with Ueberauth.Auth and Ueberauth.Failure responses.

For an example implementation see the Überauth Example application.

Calling

Depending on the configured url you can initiate the request through:

/auth/teamsnap

Or with options:

/auth/teamsnap?scope=read+write

By default the requested scope is "read". This provides read access to the TeamSnap user profile details and teams. For a read-only scope, either use "read write" or a specific write scope, such as "read write_teams". See more at TeamSnap's OAuth Documentation. Scope can be configured either explicitly as a scope query value on the request path or in your configuration:

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

License

Please see LICENSE for licensing details.