Skip to content

Commit

Permalink
Merge pull request #151 from pulibrary/omniauth-update
Browse files Browse the repository at this point in the history
Add omniauth gem
  • Loading branch information
jrgriffiniii committed Jun 4, 2024
2 parents 0203c60 + 0bf016e commit 4f54896
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ gem "honeybadger"
gem "isni"
gem "jbuilder"
gem "oauth2", "~> 2.0.x"
gem "omniauth", "~> 2.1", ">= 2.1.2"
gem "omniauth-orcid"
gem "pg"
gem "puma", "5.6.8"
Expand All @@ -25,7 +26,7 @@ gem "vite_ruby"
gem "sul_orcid_client"

# Single sign on
gem "devise"
gem "devise", "~> 4.9"
gem "omniauth-cas", "~> 3.0"

group :development, :test do
Expand All @@ -38,10 +39,10 @@ group :development, :test do
end

group :development do
gem "byebug"
gem "capistrano", "3.17.2", require: false
gem "capistrano-passenger", require: false
gem "capistrano-rails", "~> 1.6", require: false
gem "pry-byebug"
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
end
Expand Down
13 changes: 11 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ GEM
super_diff
thor
zeitwerk (~> 2.1)
coderay (1.1.3)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
commonmarker (0.23.10)
Expand Down Expand Up @@ -247,6 +248,7 @@ GEM
net-smtp
marcel (1.0.4)
matrix (0.4.2)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.23.1)
msgpack (1.7.2)
Expand Down Expand Up @@ -315,6 +317,12 @@ GEM
patience_diff (1.2.0)
optimist (~> 3.0)
pg (1.5.6)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
psych (5.1.2)
stringio
public_suffix (5.0.5)
Expand Down Expand Up @@ -503,15 +511,14 @@ DEPENDENCIES
bcrypt_pbkdf
bixby
bootsnap
byebug
capistrano (= 3.17.2)
capistrano-passenger
capistrano-rails (~> 1.6)
capybara
coveralls_reborn
database_cleaner-active_record
debug
devise
devise (~> 4.9)
ed25519
factory_bot_rails
ffaker
Expand All @@ -520,9 +527,11 @@ DEPENDENCIES
isni
jbuilder
oauth2 (~> 2.0.x)
omniauth (~> 2.1, >= 2.1.2)
omniauth-cas (~> 3.0)
omniauth-orcid
pg
pry-byebug
puma (= 5.6.8)
rack (= 2.2.8.1)
rails (~> 7.1.0)
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
# include Devise::Controllers::UrlHelpers
# include Rails.application.routes.url_helpers
# include Rails.application.routes.mounted_helpers

def new_session_path(_scope)
new_user_session_path
end

def session_path(_scope)
new_user_session_path
end

def after_sign_in_path_for(_resource)
"/users/#{@user.id}"
end
Expand Down
3 changes: 2 additions & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,11 @@

## For CAS
config.omniauth :cas, host: "fed.princeton.edu", url: "https://fed.princeton.edu/cas"
OmniAuth.config.allowed_request_methods = [:get, :post]

## For OCID Failure
config.omniauth :orcid, callback: "/auth/orcid/callback"
OmniAuth.config.allowed_request_methods = [:get, :post]
OmniAuth.config.request_validation_phase = OmniAuth::AuthenticityTokenProtection.new(allow_if: ->(_env) { true })

# ==> Mountable engine configurations
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
Expand Down
5 changes: 1 addition & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
resources :users, only: [:show]

get "orcids/:id", to: "orcids#show", as: :orcid_show
# match "/auth/orcid/callback", to: "users/omniauth_callbacks#orcid", via: [:get, :post]
match "/auth/orcid/callback", to: "orcids#create", via: [:get, :post]

get "home/index"
Expand All @@ -20,15 +19,13 @@
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check

# Defines the root path route ("/")
# root "posts#index"

root "home#index"

devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }

devise_scope :user do
get "sign_in", to: "devise/sessions#new", as: :new_user_session
get "sign_in", to: "users/omniauth_callbacks#passthru", as: :session
get "sign_out", to: "devise/sessions#destroy", as: :destroy_user_session
end
end

0 comments on commit 4f54896

Please sign in to comment.