Skip to content

Gusto/omniauth-gusto

Repository files navigation

OmniAuth Gusto

Official OmniAuth strategy for authenticating to use Gusto’s API with OAuth 2.

CircleCI

Installation

Add this line to your application's Gemfile:

gem 'omniauth-gusto'

And then execute:

$ bundle

Or install it yourself as:

$ gem install omniauth-gusto

Usage

Integrate the strategy into your middleware. Refer to Devise’s documentation if using Devise.

# config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :gusto, ENV['GUSTO_CLIENT_ID'], ENV['GUSTO_CLIENT_SECRET']
end

The route /auth/gusto will become available to initiate authentication. Set up the callback route /auth/gusto/callback and tie to a controller action to handle any post-authentication actions.

# config/routes.rb

Rails.application.routes.draw do
  get '/auth/gusto/callback', to: 'sample_controller#gusto'
end

For more information on how to use OmniAuth, refer to the OmniAuth documentation.

Gusto’s API

Use the access token from the Auth Hash request.env['omniauth.auth']['credentials']['token'] to make calls to other Gusto API endpoints such as payrolls. To gain access to Gusto’s API, contact Gusto to establish a client id and secret.

Sample Response

Below is an example Auth Hash availble in request.env['omniauth.auth']. Note info['name'] is set to the user’s email and that employee names will have to be fetched from the employees endpoint.

{
  "provider" => "gusto",
  "uid" => 123,
  "info" => {
    "email" => "example.user@gmail.com",
    "name" => "example.user@gmail.com"
  },
  "credentials" => {
    "token" => "456",
    "refresh_token" => "789",
    "expires_at" => 1561589955,
    "expires" => true
  },
  "extra" => {
    "raw_info" => {
      "id" => 123,
      "email" => "example.user@gmail.com",
      "roles" => {
        "payroll_admin" => {
          "companies" => [
            {
              "id" => 101112,
              "name" => "Poi's Doughnuts",
              "trade_name" => null,
              "locations" => [
                {
                  "id" => 131415,
                  "street_1" => "1236 Mission St",
                  "street_2" => "",
                  "city" => "San Francisco",
                  "state" => "CA",
                  "zip" => "94103",
                  "country" => "USA",
                  "active" => true
                }
              ]
            }
          ]
        }
      }
    }
  }
}

License

The gem is available as open source under the terms of the MIT License.

About

OmniAuth strategy for Gusto

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •