Skip to content

Commit

Permalink
chore: store auth errors from token request in backwards compatible w…
Browse files Browse the repository at this point in the history
…ay (#8857)
  • Loading branch information
armkeh committed Jan 23, 2025
1 parent a10f37b commit b8b79b1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions plugins/module_utils/identity/keycloak/keycloak.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ def camel(words):


class KeycloakError(Exception):
pass
def __init__(self, msg, authError=None):
self.msg = msg
self.authError = authError

def __str__(self):
return str(self.msg)


def _token_request(module_params, payload):
Expand All @@ -175,7 +180,7 @@ def _token_request(module_params, payload):
% (auth_url, str(e)))
except Exception as e:
raise KeycloakError('Could not obtain access token from %s: %s'
% (auth_url, str(e))) from e
% (auth_url, str(e)), authError=e)

try:
token = r['access_token']
Expand Down Expand Up @@ -336,7 +341,7 @@ def make_request_catching_401():
r = make_request_catching_401()
except KeycloakError as e:
# Token refresh returns 400 if token is expired/invalid, so continue on if we get a 400
if isinstance(e.__cause__, HTTPError) and e.__cause__.code != 400:
if e.authError is not None and e.authError.code != 400:
raise e

if isinstance(r, Exception):
Expand Down

0 comments on commit b8b79b1

Please sign in to comment.