AS AgentScopeAPI 手册 / API Reference

JwtService

@Service public class JwtService
源码Source io/agentscope/builder/web/auth/JwtService.java:43–104

JWT 服务,承载智能体的部署、调度与服务化运行。位于 io.agentscope.builder.web.auth 包。核心成员包括 generate、parse、extractUserId、extractRoles、JwtService。

HS256 JWT service for the claw web application.

Tokens contain the following claims:

  • sub — userId (stable identity key for HarnessAgent namespace)

  • username — display name

  • roles — list of role strings

The signing secret is read from builder.jwt.secret (with claw.jwt.secret as a legacy fallback). Defaults to a development-only placeholder — must be overridden in production.

构造器摘要Constructor Summary

构造器Constructor说明Description
public JwtService(String secret)
初始化 `JwtService` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public String generate(String userId, String username, List<String> roles)
执行 `generate` 方法。
Generates a signed JWT for the given user.
public Claims parse(String token)
设置解析。
Parses and validates a JWT, returning its claims.
public String extractUserId(Claims claims)
设置该参数。
Extracts the `userId` (subject) from a token without full validation (caller must call `#parse` for secure extraction).
public List<String> extractRoles(Claims claims)
设置该参数。
Performs the extract roles operation.

构造器详情Constructor Detail

JwtService

public JwtService(String secret)

初始化 JwtService 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
secretString密钥(类型 `String`)。The secret.
源码Source io/agentscope/builder/web/auth/JwtService.java:50–62

方法详情Method Detail

generate

public String generate(String userId, String username, List<String> roles)

执行 generate 方法。

Generates a signed JWT for the given user.

参数Parameters
名称Name类型Type说明Description
userIdString用户标识(类型 `String`)。The user id.
usernameStringusername(类型 `String`)。The username.
rolesList<String>roles(类型 `List`)。The roles.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/builder/web/auth/JwtService.java:67–77

parse

public Claims parse(String token)

设置解析。

Parses and validates a JWT, returning its claims.

参数Parameters
名称Name类型Type说明Description
tokenString令牌(类型 `String`)。The token.
返回Returns Claims
返回Claims。Returns claims.
抛出Throws
  • JwtException 当if 令牌是无效或已过期时抛出 `JwtException`。if the token is invalid or expired
源码Source io/agentscope/builder/web/auth/JwtService.java:84–86

extractUserId

public String extractUserId(Claims claims)

设置该参数。

Extracts the userId (subject) from a token without full validation (caller must call #parse for secure extraction).

参数Parameters
名称Name类型Type说明Description
claimsClaimsclaims(类型 `Claims`)。The claims.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/builder/web/auth/JwtService.java:92–94

extractRoles

public List<String> extractRoles(Claims claims)

设置该参数。

Performs the extract roles operation.

参数Parameters
名称Name类型Type说明Description
claimsClaimsclaims(类型 `Claims`)。The claims.
返回Returns List<String>
返回列出。Returns list.
源码Source io/agentscope/builder/web/auth/JwtService.java:96–103
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.