Skip to content

Commit

Permalink
Separates Non-Yale user sign in (#1036)
Browse files Browse the repository at this point in the history
Co-authored-by: JP Engstrom <jpengstrom@macbook-pro.lan>
  • Loading branch information
jpengst and JP Engstrom committed Aug 2, 2024
1 parent 4a8f9ce commit 13e3373
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions app/controllers/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,35 @@ def auth
request.env['omniauth.auth']
end

# rubocop:disable Metrics/PerceivedComplexity
def openid_connect
sub = auth.extra.raw_info.sub
yale_issuers = %w[https://auth.yale.edu/idp/shibboleth https://auth-test.yale.edu/idp/shibboleth]
yale_identity = auth.extra.raw_info.identities.find { |i| yale_issuers.include?(i.issuer) }
netid = yale_identity&.userId
@user = User.where(provider: auth.provider, uid: auth.uid, sub: sub).first
if @user.nil?
@user = User.create(
provider: auth.provider,
uid: auth.uid,
sub: sub,
netid: netid,
email: auth.info.email
)
# Login for Yale users
if auth.extra.raw_info.identities.present?
yale_issuers = %w[https://auth.yale.edu/idp/shibboleth https://auth-test.yale.edu/idp/shibboleth]
yale_identity = auth.extra.raw_info.identities.find { |i| yale_issuers.include?(i.issuer) }
netid = yale_identity&.userId
@user = User.where(provider: auth.provider, uid: auth.uid, sub: sub).first
if @user.nil?
@user = User.create(
provider: auth.provider,
uid: auth.uid,
sub: sub,
netid: netid,
email: auth.info.email
)
end
else
# Login for non-yale users without a net_id
@user = User.where(provider: auth.provider, uid: auth.uid, sub: sub).first
if @user.nil?
@user = User.create(
provider: auth.provider,
uid: auth.uid,
sub: sub,
email: auth.info.email
)
end
end

if @user
Expand All @@ -30,6 +45,7 @@ def openid_connect
redirect_to root_path
end
end
# rubocop:enable Metrics/PerceivedComplexity

protected

Expand Down

0 comments on commit 13e3373

Please sign in to comment.