Skip to content

Commit

Permalink
More adjustments of OIDC
Browse files Browse the repository at this point in the history
Just silence some internal errors when
invalid OIDC requests come in.
  • Loading branch information
prioux committed Aug 13, 2024
1 parent c91bd0a commit 2d713fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 5 additions & 6 deletions BrainPortal/app/controllers/nh_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ def orcid #:nodoc:
# a user's identity.
def nh_oidc
code = params[:code].presence.try(:strip)
state = params[:state].presence || 'wrong'
state = params[:state].presence

# Some initial simple validations
oidc = OidcConfig.find_by_state(state) if state
oidc = OidcConfig.find_by_state(state) if state
if !code || !oidc || state != oidc_current_state(oidc)
cb_error "#{oidc.name} session is out of sync with CBRAIN"
cb_error "#{oidc&.name || 'OIDC'} session is out of sync with CBRAIN"
end

# Query an OpenID provider; this returns all the info we need at the same time.
Expand Down Expand Up @@ -195,9 +195,8 @@ def nh_oidc
redirect_to signin_path
rescue => ex
clean_bt = Rails.backtrace_cleaner.clean(ex.backtrace || [])
oidc ||= OidcConfig.new.tap { |oidc| oidc.name = 'OIDC' }
Rails.logger.error "#{oidc.name} auth failed: #{ex.class} #{ex.message} at #{clean_bt[0]}"
flash[:error] = "The #{oidc.name} authentication failed"
Rails.logger.error "#{oidc&.name || 'OIDC'} auth failed: #{ex.class} #{ex.message} at #{clean_bt[0]}"
flash[:error] = "The #{oidc&.name || 'OIDC'} authentication failed"
redirect_to signin_path
end

Expand Down
9 changes: 4 additions & 5 deletions BrainPortal/app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ def destroy #:nodoc:
# a user's identity.
def oidc
code = params[:code].presence.try(:strip)
state = params[:state].presence || 'wrong'
state = params[:state].presence

# Some initial simple validations
oidc = OidcConfig.find_by_state(state) if state
if !code || !oidc || state != oidc_current_state(oidc)
cb_error "#{oidc.name} session is out of sync with CBRAIN"
cb_error "#{oidc&.name || 'OIDC'} session is out of sync with CBRAIN"
end

# Query OpenID provider; this returns all the info we need at the same time.
Expand Down Expand Up @@ -204,9 +204,8 @@ def oidc
redirect_to new_session_path
rescue => ex
clean_bt = Rails.backtrace_cleaner.clean(ex.backtrace || [])
oidc ||= OidcConfig.new.tap { |oidc| oidc.name = 'OIDC' }
Rails.logger.error "#{oidc.name} auth failed: #{ex.class} #{ex.message} at #{clean_bt[0]}"
flash[:error] = "The #{oidc.name} authentication failed"
Rails.logger.error "#{oidc&.name || 'OIDC'} auth failed: #{ex.class} #{ex.message} at #{clean_bt[0]}"
flash[:error] = "The #{oidc&.name || 'OIDC'} authentication failed"
redirect_to new_session_path
end

Expand Down

0 comments on commit 2d713fd

Please sign in to comment.