Skip to content

Commit

Permalink
Add from_omniauth_developer()
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed Mar 5, 2024
1 parent abb1d14 commit 0a78b24
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ def self.fetch_from_omniauth_saml(auth,
email_location:,
email_attribute: "emailAddress")
auth = auth.deep_symbolize_keys

case email_location
when Institution::SAMLEmailLocation::ATTRIBUTE
attrs = auth[:extra][:raw_info].attributes.deep_stringify_keys
email = attrs[email_attribute]&.first
else
email = auth[:uid]
end

User.find_by_email(email)
end

Expand Down Expand Up @@ -140,10 +138,12 @@ def self.from_autocomplete_string(string)
#
def self.from_omniauth(auth, institution:)
case auth[:provider]
when "saml", "developer"
when "saml"
User.from_omniauth_saml(auth, institution: institution)
when "identity"
User.from_omniauth_local(auth)
when "developer"
User.from_omniauth_developer(auth, institution: institution)
else
raise ArgumentError, "Unsupported auth provider"
end
Expand All @@ -168,6 +168,19 @@ def self.from_omniauth_local(auth)
user
end

##
# @private
#
def self.from_omniauth_developer(auth, institution:)
auth = auth.deep_symbolize_keys
email = auth[:info][:email]
user = User.find_by_email(email)
user ||= User.create!(institution: institution,
email: email,
name: email)
user
end

##
# @private
#
Expand Down

0 comments on commit 0a78b24

Please sign in to comment.