Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alkesh committed Jul 23, 2024
1 parent a1f0ee3 commit c88d57a
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions app/controllers/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,10 @@ def onelogin
else
request.env["omniauth.auth"]
end
core_identity_jwt = auth.extra.raw_info[ONELOGIN_JWT_CORE_IDENTITY_HASH_KEY]
if core_identity_jwt # available on second call One Login for identity verification
first_name, surname = extract_name_from_jwt(core_identity_jwt)
redirect_to(
claim_path(
journey: current_journey_routing_name,
slug: "sign-in",
claim: {
identity_confirmed_with_onelogin: true,
first_name: first_name,
surname: surname
}
)
)
else # first call to One Login for authentication
onelogin_user_info_attributes = auth.info.to_h.slice(
*SignInForm::OneloginUserInfoForm::ONELOGIN_USER_INFO_ATTRIBUTES.map(&:to_s)
)

journey_session.answers.assign_attributes(onelogin_user_info: onelogin_user_info_attributes)
journey_session.save!

redirect_to(
claim_path(
journey: current_journey_routing_name,
slug: "sign-in",
claim: {
logged_in_with_onelogin: true
}
)
)
end
core_identity_jwt = auth.extra.raw_info[ONELOGIN_JWT_CORE_IDENTITY_HASH_KEY]
return process_one_login_identity_verification_callback(core_identity_jwt) if core_identity_jwt
process_one_login_authentication_callback(auth)
rescue Rack::OAuth2::Client::Error => e
render plain: e.message
end
Expand All @@ -81,6 +53,40 @@ def current_journey_routing_name
end
end

def process_one_login_authentication_callback(auth)
onelogin_user_info_attributes = auth.info.to_h.slice(
*SignInForm::OneloginUserInfoForm::ONELOGIN_USER_INFO_ATTRIBUTES.map(&:to_s)
)

journey_session.answers.assign_attributes(onelogin_user_info: onelogin_user_info_attributes)
journey_session.save!

redirect_to(
claim_path(
journey: current_journey_routing_name,
slug: "sign-in",
claim: {
logged_in_with_onelogin: true
}
)
)
end

def process_one_login_identity_verification_callback(core_identity_jwt)
first_name, surname = extract_name_from_jwt(core_identity_jwt)
redirect_to(
claim_path(
journey: current_journey_routing_name,
slug: "sign-in",
claim: {
identity_confirmed_with_onelogin: true,
first_name: first_name,
surname: surname
}
)
)
end

def extract_name_from_jwt(jwt)
if OneLoginSignIn.bypass?
first_name = "TEST"
Expand Down

0 comments on commit c88d57a

Please sign in to comment.