-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3023 from DFE-Digital/CAPT-1766-one-login-bypass
CAPT-1766 one login bypass
- Loading branch information
Showing
20 changed files
with
333 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
class OmniauthCallbacksController < ApplicationController | ||
include JourneyConcern | ||
|
||
ONELOGIN_JWT_CORE_IDENTITY_HASH_KEY = "https://vocab.account.gov.uk/v1/coreIdentityJWT".freeze | ||
|
||
def callback | ||
auth = request.env["omniauth.auth"] | ||
|
||
|
@@ -25,6 +27,20 @@ def failure | |
render layout: false | ||
end | ||
|
||
def onelogin | ||
auth = if OneLoginSignIn.bypass? | ||
test_user_auth_hash | ||
else | ||
request.env["omniauth.auth"] | ||
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 | ||
|
||
private | ||
|
||
def current_journey_routing_name | ||
|
@@ -36,4 +52,60 @@ def current_journey_routing_name | |
Journeys::TeacherStudentLoanReimbursement::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" | ||
surname = "USER" | ||
else | ||
identity_jwt_public_key = OpenSSL::PKey::EC.new(Base64.decode64(ENV["ONELOGIN_IDENTITY_JWT_PUBLIC_KEY_BASE64"])) | ||
decoded_jwt = JSON::JWT.decode(jwt, identity_jwt_public_key) | ||
name_parts = decoded_jwt["vc"]["credentialSubject"]["name"][0]["nameParts"] | ||
first_name = name_parts.find { |part| part["type"] == "GivenName" }["value"] | ||
surname = name_parts.find { |part| part["type"] == "FamilyName" }["value"] | ||
end | ||
[first_name, surname] | ||
end | ||
|
||
def test_user_auth_hash | ||
if request.path == "/auth/onelogin" | ||
OmniAuth::AuthHash.new(info: {email: "[email protected]"}, extra: {raw_info: {}}) | ||
elsif request.path == "/auth/onelogin_identity" | ||
OmniAuth::AuthHash.new(info: {email: ""}, extra: {raw_info: {ONELOGIN_JWT_CORE_IDENTITY_HASH_KEY => "test"}}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class SignInForm < Form | ||
class OneloginUserInfoForm | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
ONELOGIN_USER_INFO_ATTRIBUTES = %i[ | ||
phone | ||
] | ||
|
||
ONELOGIN_USER_INFO_ATTRIBUTES.each do |attribute_name| | ||
attribute attribute_name | ||
end | ||
end | ||
|
||
attribute :logged_in_with_onelogin, :boolean, default: false | ||
attribute :identity_confirmed_with_onelogin, :boolean, default: false | ||
attribute :onelogin_user_info_attributes | ||
attribute :first_name | ||
attribute :surname | ||
|
||
def onelogin_user_info_attributes=(attributes) | ||
onelogin_user_info.assign_attributes( | ||
journey_session.answers.onelogin_user_info | ||
) | ||
end | ||
|
||
def onelogin_user_info | ||
@onelogin_user_info ||= OneloginUserInfoForm.new | ||
end | ||
|
||
def save | ||
journey_session.answers.assign_attributes( | ||
onelogin_user_info: onelogin_user_info.attributes, | ||
first_name: first_name, | ||
surname: surname | ||
) | ||
journey_session.save! | ||
end | ||
|
||
private | ||
|
||
def permitted_attributes | ||
super + [ | ||
onelogin_user_info_attributes: OneloginUserInfoForm::ONELOGIN_USER_INFO_ATTRIBUTES | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<h1 class="govuk-heading-l"> | ||
<% if @form.logged_in_with_onelogin %> | ||
You've successfully signed in to GOV.UK One Login | ||
<% elsif @form.identity_confirmed_with_onelogin %> | ||
You've successfully proved your identity with GOV.UK One Login | ||
<% else %> | ||
You're now going to GOV.UK One Login | ||
<% end %> | ||
</h1> | ||
|
||
<% if @form.logged_in_with_onelogin %> | ||
<p> | ||
Before you can continue your application, you'll need to prove your identity through GOV.UK One Login. | ||
</p> | ||
<p> | ||
When you've proved your identity through GOV.UK One Login, you'll return to this service to complete your applciation. | ||
</p> | ||
<% elsif @form.identity_confirmed_with_onelogin %> | ||
<p> | ||
You can now continue your application | ||
</p> | ||
<% else %> | ||
<p> | ||
To continue your application, you'll need to create a GOV.UK One Login or sign in. | ||
</p> | ||
<p> | ||
When you've signed in through GOV.UK One Login, your progress will be saved | ||
and you'll be able to return to complete your application. | ||
</p> | ||
<% end %> | ||
|
||
<div class="govuk-button-group"> | ||
<% if @form.logged_in_with_onelogin %> | ||
<%= button_to "Continue", "/auth/onelogin_identity", class: "govuk-button", method: :post %> | ||
<% elsif @form.identity_confirmed_with_onelogin %> | ||
<%= form_for @form, url: claim_path(current_journey_routing_name) do |f| %> | ||
<%= f.fields_for :onelogin_user_info do |ff| %> | ||
<% ff.object.attribute_names.each do |attribute| %> | ||
<%= ff.hidden_field attribute %> | ||
<% end %> | ||
<% end %> | ||
<%= f.hidden_field :first_name %> | ||
<%= f.hidden_field :surname %> | ||
<%= f.submit "Continue", class: "govuk-button", data: {module: "govuk-button"} %> | ||
<% end %> | ||
<% else %> | ||
<%= button_to "Continue", "/auth/onelogin", class: "govuk-button", method: :post %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% if @form.errors.any? %> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= render( | ||
"shared/error_summary", | ||
instance: @form, | ||
errored_field_id_overrides: { details_check: "claim_details_check_true" }) %> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds govuk-body"> | ||
<%= render partial: "sign_in" %> | ||
</div> | ||
</div> |
7 changes: 0 additions & 7 deletions
7
app/views/further_education_payments/claims/one_login_placeholder.html.erb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
spec/factories/journeys/further_education_payments/further_education_payments_answers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
FactoryBot.define do | ||
factory :further_education_payments_answers, class: "Journeys::FurtherEducationPayments::SessionAnswers" do | ||
trait :with_details_from_onelogin do | ||
first_name { "Jo" } | ||
surname { "Bloggs" } | ||
onelogin_user_info { {email: "[email protected]"} } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.