-
Notifications
You must be signed in to change notification settings - Fork 1
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 #2401 from DFE-Digital/AQTS-551-spike-gov-one-logi…
…n-authentication [AQTS-551] GovOne Login Authentication
- Loading branch information
Showing
25 changed files
with
483 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
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,39 @@ | ||
# frozen_string_literal: true | ||
|
||
class Teachers::OmniauthCallbacksController < ApplicationController | ||
def gov_one | ||
auth = request.env["omniauth.auth"] | ||
email = auth&.info&.email | ||
gov_one_id = auth&.uid | ||
|
||
session[:id_token] = auth&.credentials&.id_token | ||
|
||
teacher = | ||
FindOrCreateTeacherFromGovOne.call( | ||
email:, | ||
gov_one_id:, | ||
eligibility_check_id: session[:eligibility_check_id], | ||
) | ||
|
||
return error_redirect unless teacher | ||
|
||
sign_in_and_redirect teacher | ||
end | ||
|
||
def failure | ||
error_redirect | ||
end | ||
|
||
private | ||
|
||
def error_redirect | ||
return if teacher_signed_in? | ||
|
||
flash[:alert] = "There was a problem signing in. Please try again." | ||
redirect_to new_teacher_session_path | ||
end | ||
|
||
def after_sign_in_path_for(resource) | ||
stored_location_for(resource) || teacher_interface_root_path | ||
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module GovOneHelper | ||
def logout_uri | ||
params = { | ||
post_logout_redirect_uri: destroy_teacher_session_url, | ||
id_token_hint: session[:id_token], | ||
} | ||
|
||
uri = URI.parse("#{Rails.configuration.gov_one.base_uri}logout") | ||
uri.query = URI.encode_www_form(params) | ||
|
||
uri.to_s | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
class FindOrCreateTeacherFromGovOne | ||
include ServicePattern | ||
|
||
attr_reader :teacher | ||
|
||
def initialize(email:, gov_one_id:, eligibility_check_id:) | ||
@email = email | ||
@gov_one_id = gov_one_id | ||
@eligibility_check_id = eligibility_check_id | ||
end | ||
|
||
def call | ||
ActiveRecord::Base.transaction do | ||
find_or_create_teacher! | ||
|
||
create_application_form! if teacher_requires_application_form? | ||
end | ||
|
||
teacher | ||
rescue StandardError => e | ||
Sentry.capture_exception(e) | ||
|
||
nil | ||
end | ||
|
||
private | ||
|
||
attr_reader :email, :gov_one_id, :eligibility_check_id | ||
|
||
def find_or_create_teacher! | ||
@teacher = | ||
Teacher.find_by(gov_one_id:) || Teacher.find_by(email:) || | ||
Teacher.create!(email:) | ||
|
||
teacher.update!(gov_one_id:) if teacher.gov_one_id.nil? | ||
end | ||
|
||
def create_application_form! | ||
if valid_eligibility_check? | ||
ApplicationFormFactory.call(teacher:, region: eligibility_check.region) | ||
end | ||
end | ||
|
||
def valid_eligibility_check? | ||
eligibility_check.present? && eligibility_check.region.present? && | ||
eligibility_check.country.eligibility_enabled? | ||
end | ||
|
||
def eligibility_check | ||
@eligibility_check ||= EligibilityCheck.find_by(id: eligibility_check_id) | ||
end | ||
|
||
def teacher_requires_application_form? | ||
teacher.persisted? && teacher.application_form.nil? | ||
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
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,14 @@ | ||
development: | ||
base_uri: <%= ENV.fetch("GOV_ONE_OAUTH_BASE_URI", "https://oidc.integration.account.gov.uk/") %> | ||
client_id: <%= ENV["GOV_ONE_OAUTH_CLIENT_ID"] %> | ||
base_62_private_key: <%= ENV["GOV_ONE_OAUTH_BASE64_PRIVATE_KEY"] %> | ||
|
||
production: | ||
base_uri: <%= ENV["GOV_ONE_OAUTH_BASE_URI"] %> | ||
client_id: <%= ENV["GOV_ONE_OAUTH_CLIENT_ID"] %> | ||
base_62_private_key: <%= ENV["GOV_ONE_OAUTH_BASE64_PRIVATE_KEY"] %> | ||
|
||
test: | ||
base_uri: https://oidc.integration.account.gov.uk/ | ||
client_id: test | ||
base_62_private_key: test |
Oops, something went wrong.