Skip to content

Commit

Permalink
don't use Settings in ppy_auth_strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Nov 24, 2024
1 parent b7c3acc commit d95e843
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions app/lib/warden/ppy_auth_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
require 'devise/strategies/authenticatable'

class Warden::PpyAuthStrategy < Devise::Strategies::Authenticatable
LOGIN = ['/ppy_login']
LOGOUT = 'https://passportyork.yorku.ca/ppylogin/ppylogout'
CYIN = 'HTTP_PYORK_CYIN'

def valid?
Warden::PpyAuthStrategy.py_authenticated(request)
end

def authenticate!
Rails.logger.debug "start PpyAuthStrategy.authenticate"

resource = User.find_by_username user_id
resource = User.find_by_yorku_id user_id

if Warden::PpyAuthStrategy.py_authenticated(request)
alma_user = Warden::PpyAuthStrategy.find_alma_user_matching_py_cyin(request)
Expand Down Expand Up @@ -64,15 +68,13 @@ def user_id
end

def self.py_authenticated(req)
return false unless Settings.app.auth.py_authenticated_paths.include?(req.path)
header = Settings.app.auth.cas_header
req.headers[header] != nil && req.headers[header].strip != ''
return false unless LOGIN.include?(req.path)
req.headers[CYIN] != nil && req.headers[CYIN].strip != ''
end

def self.py_authenticated_user_id(req)
return nil unless Warden::PpyAuthStrategy.py_authenticated(req)
header = Settings.app.auth.cas_header
req.headers[header].strip
req.headers[CYIN].strip
end

def self.find_alma_user_matching_py_cyin(req)
Expand All @@ -98,10 +100,10 @@ def self.find_alma_user_matching_py_cyin(req)
end

def self.py_logout_url
Settings.app.auth.py_logout_url
LOGOUT
end

def self.remove_py_header_if_not_valid(req)
req.headers[Settings.app.auth.cas_header] = nil unless Warden::PpyAuthStrategy.py_authenticated(req)
req.headers[CYIN] = nil unless Warden::PpyAuthStrategy.py_authenticated(req)
end
end

0 comments on commit d95e843

Please sign in to comment.