OidcClient#

class ansys.iam.oidc.OidcClient(issuer: str | None = None, audience: str | None = None)#

Bases: OidcClientBase

OIDC client.

Overview#

validate_access_token

Validate the JSON Web Token string.

validate_token_with_introspection

Not implemented yet…

get_user_info

Retrieve user information, preferring local token claims and falling back to the

Import detail#

from ansys.iam.oidc import OidcClient

Method detail#

OidcClient.validate_access_token(value: str) → joserfc.jwt.Token#

Validate the JSON Web Token string.

The following validations are performed: exp, nbf, iss and aud.

Parameters:
value: str

text of the JWT

Returns:
Token

The validated JWT token.

Raises:
NoIssuerOrAudienceError

If the issuer URL or audience is not set.

ValueError

If the token is invalid (expired, wrong issuer, wrong audience, not yet valid, etc.).

OidcClient.validate_token_with_introspection() → None#

Not implemented yet…

OidcClient.get_user_info(access_token: str, fields: list[str] | None = None, *, from_issuer: bool = False) → ansys.iam.oidc._userinfo.UserInfo#

Retrieve user information, preferring local token claims and falling back to the OpenID Provider userinfo endpoint only when required.

Workflow:

  • Decode the access token using the provider JWKS.

  • If fields is None or empty, immediately return a UserInfo built from all claims.

  • If fields is provided and every requested field exists and is non-null in the decoded claims, return the locally built UserInfo.

  • Otherwise perform a network request to the userinfo endpoint and build UserInfo from that response.

  • If from_issuer is True, skip local token claims and perform a network request to the userinfo endpoint and build UserInfo from that response.

Field validation: any element of fields not matching a UserInfo attribute triggers a ValueError.

see also: https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse

Parameters:
access_tokenstr

The JWT access token.

fieldslist[str] | None

Fields that must be present in the local token claims to avoid the remote userinfo call.

from_issuerbool

If True, forces retrieval of user info from the identity provider, bypassing local token claims.

Returns:
UserInfo

The user information object derived from local claims or the remote endpoint.

Raises:
ValueError

If any provided field name is invalid.

NoIssuerError

If the requested fields are not present in the token and the issuer URL is not set, preventing retrieval from the identity provider.