Skip to content

ZeusWPI/omniauth-zeuswpi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 %>

About

A Zeus WPI strategy for OmniAuth 1.x

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages