Skip to main content
This script parses the incoming request’s Authorization header and extracts the user identity. It supports both Basic Auth and JWT (Bearer) formats.
Field selection: By default, the script looks at the iss (issuer) claim inside the JWT. If your username is in sub or preferred_username, update the parsed?.iss part in the code to the appropriate field.

Usage and customization

  • JWT usage: If the username is not in the iss claim, change the corresponding field (e.g. parsed?.sub) in the script after adding it.
  • Custom formats: If the header is sent without the “Basic” or “Bearer” prefix, you may need to adapt the script for that case.
  • Fallback: If the header does not match the standard formats, the first 6 characters of the current string are used as a safe fallback.

Groovy script

After adding the script, check which claim (e.g. sub, preferred_username) your Identity Provider (Keycloak, Auth0, etc.) uses in the JWT for the username.

Error cases

  • Unknown result: If the result is unknown, the script is not running, the header is empty, or the user info could not be read from the expected field.
  • Decode errors: If Base64 decoding fails, the result is null.