Current user#
The current user module provides self-management operations for the authenticated user, including offline token generation and consent management.
You access the current user through the SimAIClient.me
property.
Example#
import ansys.simai.core as asc
simai_client = asc.from_config()
# Generate an offline token
token = simai_client.me.generate_offline_token()
# List all consents
consents = simai_client.me.consents.list()
# Revoke a specific consent
simai_client.me.consents.revoke("sdk")
CurrentUser#
- class CurrentUser#
Provides access to current user self-management operations.
This class allows users to manage their own account settings, generate offline tokens, and manage consents.
Example
import ansys.simai.core as asc simai_client = asc.from_config() # Generate an offline token token = simai_client.me.generate_offline_token() # List all consents consents = simai_client.me.consents.list() for consent in consents: print(f"Client: {consent.client_id}, Created: {consent.created_date}") # Revoke a specific consent simai_client.me.consents.revoke("sdk")
- generate_offline_token() str#
Generate a new offline token for the current user.
This creates a long-lived refresh token that can be used for authentication without requiring interactive login. The token is associated with the “sdk” client ID.
- Returns:
The offline token string that can be stored and used for future authentication.
- Return type:
Example
# Generate an offline token token = simai_client.me.generate_offline_token() print(f"Store this token securely: {token}")
- property consents: ConsentDirectory#
Access consent management operations.
- Returns:
ConsentDirectoryfor managing offline access consents.
ConsentDirectory#
- class ConsentDirectory#
Provides access to consent management operations.
Consents represent the authorization records that grant a client (like the SDK) permission to use offline tokens for authentication.
Example
import ansys.simai.core as asc simai_client = asc.from_config() # List all consents consents = simai_client.me.consents.list() for consent in consents: print(f"Client: {consent.client_id}, Created: {consent.created_date}") # Revoke a specific consent simai_client.me.consents.revoke("sdk")
- list() List[Consent]#
List all offline access consents for the current user.
- Returns:
List of
Consentobjects representing the user’s offline access consents.- Return type:
Example
consents = simai_client.me.consents.list() for consent in consents: print(f"Client: {consent.client_id}") print(f" Created: {consent.created_date}") print(f" Scopes: {consent.granted_scopes}")
- revoke(client_id: str) None#
Revoke an offline access consent for the current user.
This will invalidate the consent associated with the given client ID, preventing any further use of offline tokens for that client.
- Parameters:
client_id (str) – The client ID of the consent to revoke.
- Raises:
NotFoundError – If no consent exists for the given client ID.
Example
# Revoke consent for the SDK client simai_client.me.consents.revoke("sdk")
Warning
Revoking a consent will invalidate any offline tokens associated with that client. Server-side workflows using those tokens will stop working.
Consent#
- class Consent#
Represents a consent granted by the current user to a client (like the SDK).