Skip to content

Latest commit

 

History

History
75 lines (57 loc) · 1.73 KB

README.md

File metadata and controls

75 lines (57 loc) · 1.73 KB

Gem Version

OmniAuth Zeus WPI Zauth Strategy

Strategy to authenticate with Zeus WPI via OAuth2 in OmniAuth, powered by Zauth.

Installation

Add to your Gemfile

gem 'omniauth-oauth2'
gem 'omniauth-zeuswpi'
gem 'omniauth-rails_csrf_protection'

And run bundle install

Usage

Note: Change User to your specific User model

  1. Add the strategy to the omniauth config:
config.omniauth :zeuswpi,
  Rails.application.credentials.omniauth_client_id,
  Rails.application.credentials.omniauth_client_secret,
  token_params: { parse: :json }
  1. Add a callbacks controller:
class CallbacksController < Devise::OmniauthCallbacksController
  # See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy
  skip_before_action :verify_authenticity_token, only: :zeuswpi

  def zeuswpi
    @user = User.from_omniauth(request.env["omniauth.auth"])
    sign_in_and_redirect @user, event: :authentication
  end

  def after_omniauth_failure_path_for(scope)
    root_path
  end
end
  1. Add the Devise Omniauth routes:
devise_for :users, controllers: {
  omniauth_callbacks: 'callbacks'
}
  1. Make your User model omniauthable:
devise :omniauthable, omniauth_providers: %i[zeuswpi]
  1. Add the from_omniauth helper to your User model:
def self.from_omniauth(auth)
  where(name: auth.uid).first_or_create do |user|
    user.name = auth.uid
  end
end
  1. Add a button to your website:
<%= button_to "Log in with Zeus WPI",
              user_zeuswpi_omniauth_authorize_path %>