agentscope.studio.utils module

This module provides utilities for securing views in a web application with authentication and authorization checks.

Functions:
_require_auth - A decorator for protecting views by requiring

authentication.

agentscope.studio.utils.generate_jwt(user_login: str, access_token: str, verification_token: str, secret_key: str, version: str | None = None) str[source]

Generates a JSON Web Token (JWT) with the specified payload.

Parameters:
  • user_login (str) – The user’s login or identifier.

  • access_token (str) – The access token associated with the user.

  • verification_token (str) – A verification token for additional security.

  • secret_key (str) – The secret key used to sign the JWT.

  • version (str, optional) – Optional version of the token.

Returns:

The encoded JWT as a string.

Return type:

str

agentscope.studio.utils.decode_jwt(token: str, secret_key: str) Any[source]

Decodes a JSON Web Token (JWT) using the provided secret key.

Parameters:
  • token (str) – The encoded JWT to decode.

  • secret_key (str) – The secret key used for decoding the JWT.

Returns:

The payload of the decoded token if successful.

Return type:

dict

Raises:
  • abort – If the token is expired or invalid, a 401 or 403 error is

  • raised.