-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ER-892-assessment-result-banner-html-css-update
- Loading branch information
Showing
50 changed files
with
1,113 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
--markup markdown | ||
- | ||
cms/*.md | ||
gov_one_login/*.md | ||
data/*.md | ||
uml/*.md | ||
adr/*.md | ||
|
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,19 @@ | ||
# GOV.UK One Login | ||
|
||
* Status: accepted | ||
|
||
## Context and Problem Statement | ||
The integration of GOV.UK One Login user authentication is a requirement of the service going live. This single sign on will allow users to login to the service using their GOV.UK One Login account. | ||
|
||
## Decision Drivers | ||
* GOV.UK One Login reccomends using an off-the-shelf OIDC library | ||
* We currently use Devise for user authentication | ||
* Omniauth would allow us to use Devise and integrate with GOV.UK One Login | ||
|
||
## Considered Options | ||
* [omniauth](https://github.com/omniauth/omniauth) | ||
* [omniauth_openid_connect](https://github.com/omniauth/omniauth_openid_connect) | ||
|
||
## Decision Outcome | ||
Chosen option: [omniauth_openid_connect](https://github.com/omniauth/omniauth_openid_connect) | ||
|
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,7 @@ | ||
class GovOneController < ApplicationController | ||
layout 'hero' | ||
|
||
def show | ||
redirect_to my_modules_path if current_user | ||
end | ||
end |
35 changes: 35 additions & 0 deletions
35
app/controllers/registration/terms_and_conditions_controller.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Registration | ||
class TermsAndConditionsController < BaseController | ||
def edit; end | ||
|
||
def update | ||
form.terms_and_conditions_agreed_at = user_params[:terms_and_conditions_agreed_at] | ||
|
||
if form.save | ||
if current_user.registration_complete? | ||
redirect_to user_path, notice: t(:details_updated) | ||
else | ||
redirect_to edit_registration_name_path | ||
end | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
# @return [Hash] | ||
def user_params | ||
params.require(:user).permit(:terms_and_conditions_agreed_at) | ||
end | ||
|
||
# @return [Registration::NameForm] | ||
def form | ||
@form ||= | ||
TermsAndConditionsForm.new( | ||
user: current_user, | ||
terms_and_conditions_agreed_at: current_user.terms_and_conditions_agreed_at, | ||
) | ||
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,104 @@ | ||
# Controller handling OmniAuth callbacks for user authentication. | ||
# This controller uses the GovOneAuthService to retrieve user informaton and create or sign in an user based on the email address or gov one id | ||
|
||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
# This method is called by Devise after successful Gov One Login authentication | ||
# @return [nil] | ||
def openid_connect | ||
if params['error'].present? | ||
Rails.logger.error("Authentication error: #{params['error']}, #{params['error_description']}") | ||
return error_redirect | ||
end | ||
|
||
return error_redirect unless session_params? && valid_params? | ||
|
||
auth_service = GovOneAuthService.new(code: params['code']) | ||
tokens_response = auth_service.tokens | ||
return error_redirect unless valid_tokens?(tokens_response) | ||
|
||
id_token = auth_service.decode_id_token(tokens_response['id_token'])[0] | ||
return error_redirect unless valid_id_token?(id_token) | ||
|
||
session[:id_token] = tokens_response['id_token'] | ||
gov_one_id = id_token['sub'] | ||
|
||
user_info_response = auth_service.user_info(tokens_response['access_token']) | ||
email = user_info_response['email'] | ||
return error_redirect unless valid_user_info?(user_info_response, gov_one_id) | ||
|
||
gov_user = User.find_or_create_from_gov_one(email: email, gov_one_id: gov_one_id) | ||
|
||
delete_session_params | ||
sign_in_and_redirect gov_user if gov_user | ||
end | ||
|
||
private | ||
|
||
# @return [Boolean] | ||
def valid_params? | ||
params['code'].present? && params['state'].present? && params['state'] == session[:gov_one_auth_state] | ||
end | ||
|
||
# @return [Boolean] | ||
def session_params? | ||
session[:gov_one_auth_state].present? && session[:gov_one_auth_nonce].present? | ||
end | ||
|
||
# @param tokens_response [Hash] | ||
# @return [Boolean] | ||
def valid_tokens?(tokens_response) | ||
tokens_response.present? && | ||
tokens_response['access_token'].present? && | ||
tokens_response['id_token'].present? && | ||
tokens_response['error'].blank? | ||
end | ||
|
||
# @param id_token [Hash] | ||
# @return [Boolean] | ||
def valid_id_token?(id_token) | ||
id_token.present? && | ||
id_token['nonce'] == session[:gov_one_auth_nonce] && | ||
id_token['iss'] == "#{Rails.application.config.gov_one_base_uri}/" && | ||
id_token['aud'] == Rails.application.config.gov_one_client_id | ||
end | ||
|
||
# @param user_info_response [Hash] | ||
# @return [Boolean] | ||
def valid_user_info?(user_info_response, gov_one_id) | ||
user_info_response.present? && | ||
user_info_response['email'].present? && | ||
user_info_response['sub'] == gov_one_id && | ||
user_info_response['error'].blank? | ||
end | ||
|
||
# @return [nil] | ||
def error_redirect | ||
flash[:alert] = 'There was a problem signing in. Please try again.' | ||
redirect_to root_path | ||
end | ||
|
||
# @return [nil] | ||
def delete_session_params | ||
session.delete(:gov_one_auth_state) | ||
session.delete(:gov_one_auth_nonce) | ||
end | ||
|
||
# @return [String] | ||
def after_sign_in_path_for(resource) | ||
if resource.registration_complete? | ||
if resource.display_whats_new? | ||
resource.display_whats_new = false | ||
resource.save! | ||
static_path('whats-new') | ||
elsif !resource.email_preferences_complete? | ||
static_path('email-preferences') | ||
else | ||
my_modules_path | ||
end | ||
elsif resource.private_beta_registration_complete? | ||
static_path('new-registration') | ||
else | ||
edit_registration_terms_and_conditions_path | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Registration | ||
class TermsAndConditionsForm < BaseForm | ||
attr_accessor :terms_and_conditions_agreed_at | ||
|
||
validates :terms_and_conditions_agreed_at, presence: true | ||
|
||
# @return [Boolean] | ||
def save | ||
return false unless valid? | ||
|
||
user.update!(terms_and_conditions_agreed_at: terms_and_conditions_agreed_at) | ||
end | ||
end | ||
end |
Oops, something went wrong.