[24.1] prevent "missing refresh_token" errors by supporting <extra_scopes> also with Keycloak backend #18826
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.
The <extra_scopes> attribute of oidc_backend_config.xml is not supported in the Keycloak backend. Consequently, it was not possible to request 'offline_access' from the IdP, which is expected in the current implementation, and we kept receiving:
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: Traceback (most recent call last):
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: File "/srv/galaxy/server/lib/galaxy/authnz/managers.py", line 357, in refresh_expiring_oidc_tokens_for_provider
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: refreshed = backend.refresh(trans, auth)
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: File "/srv/galaxy/server/lib/galaxy/authnz/custos_authnz.py", line 140, in refresh
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: token = oauth2_session.refresh_token(token_endpoint, **params)
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: File "/srv/galaxy/venv/lib/python3.9/site-packages/requests_oauthlib/oauth2_session.py", line 496, in refresh_token
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: self.token = self._client.parse_request_body_response(r.text, scope=self.scope)
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: File "/srv/galaxy/venv/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 427, in parse_request_body_response
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: self.token = parse_token_response(body, scope=scope)
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: File "/srv/galaxy/venv/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in parse_token_response
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: validate_token_parameters(params)
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: File "/srv/galaxy/venv/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 448, in validate_token_parameters
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: raise_from_error(params.get('error'), params)
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: File "/srv/galaxy/venv/lib/python3.9/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 399, in raise_from_error
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: raise cls(**kwargs)
Sep 16 11:23:37 usegalaxy-test galaxyctl[11560]: oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) refresh_token parameter not provided
The patch is conservative, unless <extra_scopes> appears in the config, it does nothing.