You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm overriding the process_request method of SessionRefresh to dynamically add a parameter kc_idp_hint. This parameter is different for each user, so I can't use OIDC_AUTH_REQUEST_EXTRA_PARAMS. There should be an easier way to add parameters to a subclassed SessionRefresh.
fromdjango.urlsimportreversefromdjango.utils.functionalimportcached_propertyfrommozilla_django_oidc.middlewareimportSessionRefreshfromdjango.confimportsettingsclassCustomSessionRefresh(SessionRefresh):
""" This class extends the SessionRefresh middleware. """defprocess_request(self, request):
""" Override the process_request method to add kc_idp_hint to the OIDC_AUTH_REQUEST_EXTRA_PARAMS. """ifrequest.user.is_authenticatedandnotrequest.user.is_anonymous:
# NOTE: Modifying settings dynamically isn't good, but needed here to avoid code duplicationsettings.OIDC_AUTH_REQUEST_EXTRA_PARAMS= {
"kc_idp_hint": request.user.userprofile.keycloak_identity_provider.name,
}
returnsuper().process_request(request)
The text was updated successfully, but these errors were encountered:
jordan-owen
changed the title
Allow SessionRefresh middleware subclass to easily set dynamic request parameters
Allow SessionRefresh middleware subclass to easily accept dynamic request parameters in process_request method
Mar 6, 2024
I'm overriding the
process_request
method of SessionRefresh to dynamically add a parameterkc_idp_hint
. This parameter is different for each user, so I can't useOIDC_AUTH_REQUEST_EXTRA_PARAMS
. There should be an easier way to add parameters to a subclassed SessionRefresh.The text was updated successfully, but these errors were encountered: