-
Notifications
You must be signed in to change notification settings - Fork 8
WIP: Spike remove gds sso #769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
thomasiles
wants to merge
4
commits into
main
Choose a base branch
from
spike-remove-gds-sso
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -56,7 +56,7 @@ def support_navigation_item | |
def profile_navigation_item | ||
return nil if user.name.blank? | ||
|
||
NavigationItem.new(text: user.name, href: user_profile_url, active: false) | ||
NavigationItem.new(text: user.name, href: nil, active: false) | ||
end | ||
|
||
def signout_navigation_item | ||
|
@@ -70,22 +70,11 @@ def user_provider | |
end | ||
|
||
def signout_url | ||
if user_provider == :gds | ||
gds_sign_out_path | ||
elsif %i[auth0 cddo_sso mock_gds_sso].include? user_provider | ||
if %i[auth0 mock_gds_sso].include? user_provider | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be updated |
||
sign_out_path | ||
end | ||
end | ||
|
||
def user_profile_url | ||
case user_provider | ||
when :cddo_sso | ||
"https://sso.service.security.gov.uk/profile" | ||
when :gds | ||
GDS::SSO::Config.oauth_root_url | ||
end | ||
end | ||
|
||
def should_show_user_profile_link? | ||
Pundit.policy(user, :user).can_manage_user? | ||
end | ||
|
This file contains hidden or 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,8 +1,42 @@ | ||
Rails.application.config.before_initialize do | ||
# Configure OmniAuth authentication middleware | ||
# add Auth0 provider | ||
Rails.application.config.app_middleware.use( | ||
OmniAuth::Strategies::Auth0, | ||
require "warden" | ||
|
||
OmniAuth.config.logger = Rails.logger | ||
|
||
Warden::Manager.after_authentication do |user, _auth, _opts| | ||
# We've successfully signed in. | ||
# If they were remotely signed out, clear the flag as they're no longer suspended | ||
user.clear_remotely_signed_out! | ||
end | ||
|
||
Warden::Manager.serialize_into_session do |user| | ||
if user.respond_to?(:uid) && user.uid | ||
[user.uid, Time.zone.now.utc.iso8601] | ||
end | ||
end | ||
|
||
Warden::Manager.serialize_from_session do |(uid, auth_timestamp)| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could add more tests around these parts lifted from gds_sso |
||
# This will reject old sessions that don't have a previous login timestamp | ||
if auth_timestamp.is_a?(String) | ||
begin | ||
auth_timestamp = Time.zone.parse(auth_timestamp) | ||
rescue ArgumentError | ||
auth_timestamp = nil | ||
end | ||
end | ||
|
||
if auth_timestamp && ((auth_timestamp + Settings.auth_valid_for) > Time.zone.now.utc) | ||
User.where(uid:, remotely_signed_out: false).first | ||
end | ||
end | ||
|
||
Rails.application.config.app_middleware.use Warden::Manager do |warden| | ||
warden.default_strategies(Settings.auth_provider.to_sym, :gds_bearer_token) | ||
warden.failure_app = AuthenticationController | ||
end | ||
|
||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider( | ||
:auth0, | ||
Settings.auth0.client_id, | ||
Settings.auth0.client_secret, | ||
Settings.auth0.domain, | ||
|
@@ -12,35 +46,6 @@ | |
connection: "email", # default to using the passwordless flow | ||
}, | ||
) | ||
|
||
# add CDDO SSO provider | ||
Rails.application.config.app_middleware.use( | ||
OmniAuth::Strategies::OpenIDConnect, | ||
name: :cddo_sso, | ||
issuer: "https://sso.service.security.gov.uk", | ||
discovery: true, | ||
require_state: true, | ||
|
||
scope: %i[openid email profile], | ||
client_options: { | ||
identifier: Settings.cddo_sso.identifier, | ||
secret: Settings.cddo_sso.secret, | ||
}, | ||
) | ||
|
||
# Configure Warden session management middleware | ||
# swap out the Warden::Manager installed by `gds-sso` gem | ||
Rails.application.config.app_middleware.swap Warden::Manager, Warden::Manager do |warden| | ||
warden.default_strategies(Settings.auth_provider.to_sym, :gds_bearer_token) | ||
warden.failure_app = AuthenticationController | ||
end | ||
|
||
GDS::SSO::Config.auth_valid_for = Settings.auth_valid_for | ||
end | ||
|
||
# Monkeypatch omniauth_openid_connect | ||
class OmniAuth::Strategies::OpenIDConnect | ||
def redirect_uri | ||
callback_url | ||
end | ||
end | ||
OmniAuth.config.allowed_request_methods = %i[post get] |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 @@ | ||
Warden::Strategies.add(:mock_user) do | ||
def authenticate! | ||
logger.warn("Authenticating with mock_gds_sso strategy") | ||
|
||
test_user ||= User.first | ||
|
||
if test_user | ||
success!(test_user) | ||
elsif Rails.env.test? && ENV["GDS_SSO_MOCK_INVALID"].present? | ||
fail!(:invalid) | ||
else | ||
raise "Mock_user running in mock mode and no test user found. Normally we'd load the first user in the database. Create a user in the database." | ||
end | ||
end | ||
end |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -9,4 +9,4 @@ forms_api: | |
auth_key: changeme | ||
|
||
# Use mock authentication | ||
auth_provider: mock_gds_sso | ||
auth_provider: mock_user |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why update_attribute is used here - maybe to make sure it happens despite the state the user is in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need the
remotely_signed_out!
stuff? The existing stuff is reliant on the GOV.UK Signon servers calling an API exposed by gds_sso gem.