Skip to content

Commit 6566dca

Browse files
committed
docs(users): Match comments wrt SAML with openHPI
1 parent 199e551 commit 6566dca

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

app/controllers/users/omniauth_callbacks_controller.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ def set_flash(type, key, kind: OmniAuth::Utils.camelize(omniauth_provider), reas
131131
end
132132

133133
def current_user
134-
# Check if an existing user is already signed in (passed through the RelayState)
135-
# and trying to add a new identity to their account. If so, we load the user information
136-
# and set it as the current user. This is necessary to avoid creating a new user.
134+
# Check if an existing user is already signed in and trying to add a new identity to their account;
135+
# the session ID is passed through the RelayState then (see the `AbstractSaml` strategy).
136+
#
137+
# If the RelayState contains the ID of the current user, we pass it on, so that the middleware can find the
138+
# current user. This is necessary to avoid creating a new user.
137139
@current_user ||= User.find_by(id: OmniAuth::NonceStore.pop(params[:RelayState])) || super
138140
end
139141

lib/omni_auth/strategies/abstract_saml.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ class AbstractSaml < OmniAuth::Strategies::SAML
2525
want_assertions_encrypted: true, # Invalidate SAML messages without an EncryptedAssertion
2626
}
2727

28-
# Our auto-login mechanism passes a desired application state to the request phase.
29-
# So far, this is used to store a temporary token for the current user in the RelayState.
30-
# If we forward this via SAML's standard "RelayState" parameter, we will
31-
# get it back in the callback phase.
28+
# During the request phase, we store the ID of the current user in the `request.params`.
29+
# It is passed through via SAML's standard `RelayState` parameter, so it will be preserved and can be used in the
30+
# callback phase.
3231
option :idp_sso_service_url_runtime_params, {
3332
relay_state: 'RelayState',
3433
}
@@ -81,9 +80,8 @@ def with_settings # rubocop:disable Metrics/AbcSize
8180
options[:slo_default_relay_state] ||= full_host
8281

8382
if on_request_path? && current_user
84-
# We want to store the current user in the SAML RelayState,
85-
# so that we can auto-login the user in the callback phase.
86-
# This allows a registered user to add further OmniAuth providers.
83+
# Store the ID of the current user in the SAML RelayState if a user is logged in, so that it can be accessed
84+
# for requesting the current user in the callback phase and to add the new identity to the existing account.
8785
request.params['relay_state'] = NonceStore.add current_user.id
8886
end
8987
super

0 commit comments

Comments
 (0)