Skip to content

Commit

Permalink
show errors for sso failure, handle sso from users with an existing e…
Browse files Browse the repository at this point in the history
…mail address
  • Loading branch information
orangewolf authored and bkiahstroud committed Mar 1, 2024
1 parent 85c072b commit 1668065
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
9 changes: 4 additions & 5 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def callback
# where we want a JS-based redirect to go.
render 'complete', locals: { redirect_to_url: url || hyrax.dashboard_path }
else
session['devise.user_attributes'] = @user.attributes
redirect_to new_user_registration_url
redirect_to root_path, flash: {error: 'Not able to log in user. #{@user.errors.full_messages}'}
end
end
alias cas callback
Expand All @@ -42,8 +41,8 @@ def passthru
render status: 404, plain: 'Not found. Authentication passthru.'
end

# def failure
# #redirect_to root_path
# end
def failure
redirect_to root_path, flash: {error: 'Authentication Failed. Something is wrong with the SSO configuration.'}
end
end
end
31 changes: 17 additions & 14 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ def self.default_scope
scope :registered, -> { for_repository.group(:id).where(guest: false) }

def self.from_omniauth(auth)
find_or_create_by(provider: auth.provider, uid: auth.uid) do |user|
user.email = auth&.info&.email
user.email ||= auth.uid
# rubocop:disable Performance/RedundantMatch
user.email = [auth.uid, '@', Site.instance.account.email_domain].join unless user.email.match('@')
# rubocop:enable Performance/RedundantMatch
user.password = Devise.friendly_token[0, 20]
user.display_name = auth&.info&.name # assuming the user model has a name
user.display_name ||= "#{auth&.info&.first_name} #{auth&.info&.last_name}" if auth&.info&.first_name && auth&.info&.last_name
# user.image = auth.info.image # assuming the user model has an image
# If you are using confirmable and the provider(s) you use validate emails,
# uncomment the line below to skip the confirmation emails.
# user.skip_confirmation!
end
u = find_by(provider: auth.provider, uid: auth.uid)
return u if u

u = find_by(email: auth&.info&.email&.downcase)
u ||= new
u.provider = auth.provider
u.uid = auth.uid
u.email = auth&.info&.email
u.email ||= auth.uid
# rubocop:disable Performance/RedundantMatch
u.email = [auth.uid, '@', Site.instance.account.email_domain].join unless u.email.match('@')
# rubocop:enable Performance/RedundantMatch
u.password = Devise.friendly_token[0, 20] if u.new_record?
u.display_name = auth&.info&.name # assuming the user model has a name
u.display_name ||= "#{auth&.info&.first_name} #{auth&.info&.last_name}" if auth&.info&.first_name && auth&.info&.last_name
u.save
u
end

# Method added by Blacklight; Blacklight uses #to_s on your
Expand Down

0 comments on commit 1668065

Please sign in to comment.