-
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 pull request #63 from DFE-Digital/98-integrate-dfe-signin
[98] Integrate DfE sign in
- Loading branch information
Showing
28 changed files
with
437 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
BYPASS_DSI=true | ||
HOSTING_ENVIRONMENT=local | ||
DFE_SIGN_IN_CLIENT_ID=checkchildrensbarredlist | ||
DFE_SIGN_IN_REDIRECT_URL=http://localhost:3000/auth/dfe/callback | ||
DFE_SIGN_IN_SECRET=override-locally | ||
DFE_SIGN_IN_ISSUER=https://dev-oidc.signin.education.gov.uk |
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class OmniauthCallbacksController < ApplicationController | ||
protect_from_forgery except: :dfe_bypass | ||
skip_before_action :authenticate_dsi_user! | ||
skip_before_action :handle_expired_session! | ||
|
||
def dfe | ||
@dsi_user = DsiUser.create_or_update_from_dsi(request.env["omniauth.auth"]) | ||
session[:dsi_user_id] = @dsi_user.id | ||
session[:dsi_user_session_expiry] = 2.hours.from_now.to_i | ||
|
||
redirect_to root_path | ||
end | ||
alias_method :dfe_bypass, :dfe | ||
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,7 @@ | ||
class SignInController < ApplicationController | ||
skip_before_action :authenticate_dsi_user! | ||
skip_before_action :handle_expired_session! | ||
|
||
def new | ||
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,7 @@ | ||
class SignOutController < ApplicationController | ||
skip_before_action :handle_expired_session! | ||
|
||
def new | ||
session[:dsi_user_id] = nil if dsi_user_signed_in? | ||
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,7 @@ | ||
require "hosting_environment" | ||
|
||
class DfESignIn | ||
def self.bypass? | ||
HostingEnvironment.test_environment? && ENV["BYPASS_DSI"] == "true" | ||
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,21 @@ | ||
# frozen_string_literal: true | ||
module HostingEnvironment | ||
TEST_ENVIRONMENTS = %w[local test preproduction review].freeze | ||
PRODUCTION_URL = I18n.t("service.url") | ||
|
||
def self.host | ||
ENV.fetch("HOSTING_DOMAIN") | ||
end | ||
|
||
def self.environment_name | ||
ENV.fetch("HOSTING_ENVIRONMENT", "unknown-environment") | ||
end | ||
|
||
def self.test_environment? | ||
TEST_ENVIRONMENTS.include?(HostingEnvironment.environment_name) | ||
end | ||
|
||
def self.production? | ||
environment_name == "production" | ||
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,13 @@ | ||
class DsiUser < ApplicationRecord | ||
def self.create_or_update_from_dsi(dsi_payload) | ||
dsi_user = find_or_initialize_by(email: dsi_payload.info.fetch(:email)) | ||
|
||
dsi_user.update!( | ||
first_name: dsi_payload.info.first_name, | ||
last_name: dsi_payload.info.last_name, | ||
uid: dsi_payload.uid | ||
) | ||
|
||
dsi_user | ||
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,26 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-l">Sign in</h1> | ||
|
||
<p class="govuk-body"> | ||
You can use this service if you’re: | ||
</p> | ||
<ul class="govuk-list govuk-list--bullet"> | ||
<li> | ||
waiting for the result of a DBS check for a new employee | ||
</li> | ||
<li> | ||
checking the status of an employee who worked in a school or college less than 3 months ago | ||
</li> | ||
</ul> | ||
|
||
<%= form_with url: (DfESignIn.bypass? ? "/auth/developer" : "/auth/dfe") do |f| %> | ||
<button type="submit" class="govuk-button govuk-button--start"> | ||
<%= DfESignIn.bypass? ? "Sign in with DSI bypass" : "Sign in" %> | ||
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false"> | ||
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z"></path> | ||
</svg> | ||
</button> | ||
<% end %> | ||
</div> | ||
</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,7 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-xl">You are now signed out</h1> | ||
|
||
<%= govuk_button_link_to "Continue", root_path %> | ||
</div> | ||
</div> |
Oops, something went wrong.