-
Notifications
You must be signed in to change notification settings - Fork 166
Refactor fetching of SP attributes #1167
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,15 @@ | ||
| class ApplicationController < ActionController::Base # rubocop:disable Metrics/ClassLength | ||
| include BrandedExperience | ||
| class ApplicationController < ActionController::Base | ||
| include UserSessionContext | ||
|
|
||
| # Prevent CSRF attacks by raising an exception. | ||
| # For APIs, you may want to use :null_session instead. | ||
| protect_from_forgery with: :exception | ||
|
|
||
| rescue_from ActionController::InvalidAuthenticityToken, | ||
| with: :invalid_auth_token | ||
| rescue_from ActionController::InvalidAuthenticityToken, with: :invalid_auth_token | ||
|
|
||
| helper_method :decorated_user, :reauthn?, :user_fully_authenticated? | ||
| helper_method :decorated_session, :decorated_user, :reauthn?, :user_fully_authenticated? | ||
|
|
||
| before_action :create_branded_experience | ||
| prepend_before_action :session_expires_at | ||
| before_action :set_locale | ||
|
|
||
|
|
@@ -44,36 +43,29 @@ def create_user_event(event_type, user = current_user) | |
| Event.create(user_id: user.id, event_type: event_type) | ||
| end | ||
|
|
||
| def decorated_session | ||
| @_decorated_session ||= DecoratedSession.new(sp: current_sp, view_context: view_context).call | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def redirect_on_timeout | ||
| params = request.query_parameters | ||
| return unless params[:timeout] | ||
|
|
||
| params[:issuer].present? ? redirect_with_sp : redirect_without_sp | ||
| end | ||
|
|
||
| def sp_metadata | ||
| ServiceProvider.from_issuer(request.query_parameters[:issuer]).metadata | ||
| flash[:timeout] = decorated_session.timeout_flash_text | ||
|
||
| redirect_to url_for(params.except(:timeout)) | ||
| end | ||
|
|
||
| def sp_name | ||
| sp_metadata[:friendly_name] || sp_metadata[:agency] | ||
| def current_sp | ||
| @current_sp ||= sp_from_sp_session || sp_from_params | ||
| end | ||
|
|
||
| def redirect_with_sp # rubocop:disable Metrics/AbcSize | ||
| flash[:timeout] = t( | ||
| 'notices.session_cleared_with_sp', | ||
| link: view_context.link_to(sp_name, sp_metadata[:return_to_sp_url]), | ||
| minutes: Figaro.env.session_timeout_in_minutes, | ||
| sp: sp_name | ||
| ) | ||
| redirect_to url_for(request.query_parameters.except(:timeout)) | ||
| def sp_from_sp_session | ||
| ServiceProvider.from_issuer(sp_session[:issuer]) | ||
| end | ||
|
|
||
| def redirect_without_sp | ||
| flash[:timeout] = t('notices.session_cleared', minutes: Figaro.env.session_timeout_in_minutes) | ||
| redirect_to url_for(request.query_parameters.except(:issuer, :timeout)) | ||
| def sp_from_params | ||
| ServiceProvider.from_issuer(params[:issuer]) | ||
| end | ||
|
|
||
| def decorated_user | ||
|
|
@@ -137,4 +129,12 @@ def set_locale | |
| def sp_session | ||
| session.fetch(:sp, {}) | ||
| end | ||
|
|
||
| def create_branded_experience | ||
| return unless session[:sp] | ||
|
|
||
| @sp_logo = current_sp.logo | ||
|
||
| @sp_name = decorated_session.sp_name | ||
|
||
| @sp_return_url = current_sp.return_to_sp_url | ||
| end | ||
| end | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,15 @@ | ||
| class OpenidConnectAuthorizeDecorator | ||
| attr_reader :scopes, :service_provider | ||
| attr_reader :requested_attributes | ||
|
|
||
| delegate :metadata, to: :service_provider | ||
|
|
||
| def initialize(scopes:, service_provider:) | ||
| def initialize(scopes:) | ||
| @scopes = scopes | ||
| @service_provider = service_provider | ||
| end | ||
|
|
||
| def name | ||
| metadata[:friendly_name] || metadata[:agency] | ||
| end | ||
|
|
||
| def requested_attributes | ||
| OpenidConnectAttributeScoper.new(scopes).requested_attributes | ||
|
Contributor
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 line is the only thing this class does anymore, should we just remove the class entirely and write a
Contributor
Author
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. Agreed. Can we do that in a follow-up PR?
Contributor
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. SGTM! |
||
| end | ||
|
|
||
| def logo | ||
| metadata[:logo] | ||
| end | ||
| private | ||
|
|
||
| attr_reader :scopes | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,12 @@ def idv_hardfail4_partial | |
| end | ||
|
|
||
| def logo_partial; end | ||
|
|
||
| def timeout_flash_text | ||
| I18n.t('notices.session_cleared', minutes: Figaro.env.session_timeout_in_minutes) | ||
| end | ||
|
|
||
| def sp_name | ||
| nil | ||
|
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| class DecoratedSession | ||
| def initialize(sp:, view_context:) | ||
| @sp = sp | ||
| @view_context = view_context | ||
| end | ||
|
|
||
| def call | ||
| if sp.is_a? ServiceProvider | ||
|
||
| ServiceProviderSessionDecorator.new(sp: sp, view_context: view_context) | ||
| else | ||
| SessionDecorator.new | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :sp, :view_context | ||
| end | ||
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.
💪