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 [源代码]
Generates a JSON Web Token (JWT) with the specified payload.
- 参数:
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.
- 返回:
The encoded JWT as a string.
- 返回类型:
str
- agentscope.studio.utils.decode_jwt(token: str, secret_key: str) Any [源代码]
Decodes a JSON Web Token (JWT) using the provided secret key.
- 参数:
token (str) – The encoded JWT to decode.
secret_key (str) – The secret key used for decoding the JWT.
- 返回:
The payload of the decoded token if successful.
- 返回类型:
dict
- 抛出:
abort – If the token is expired or invalid, a 401 or 403 error is
raised. –