认证 API
登录
http
POST /api/v1/auth/login
Content-Type: application/json
{
"email": "admin@example.com",
"password": "admin123"
}响应 200 OK
json
{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer"
}注册
http
POST /api/v1/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "securepassword",
"full_name": "John Doe"
}响应 201 Created
json
{
"id": "uuid",
"email": "user@example.com",
"full_name": "John Doe",
"role": "viewer"
}获取当前用户
http
GET /api/v1/auth/me
Authorization: Bearer <token>响应 200 OK
json
{
"id": "uuid",
"email": "admin@example.com",
"full_name": "Admin User",
"role": "admin"
}使用令牌
在所有需要认证的请求中,将 JWT 令牌放入 Authorization 头:
bash
curl -H "Authorization: Bearer eyJ..." https://api.forgexa.net/api/v1/workspaces令牌默认 24 小时过期(可通过 ACCESS_TOKEN_EXPIRE_MINUTES 配置)。刷新令牌有效期 30 天。
个人访问令牌(PAT)
对于程序化访问(CI/CD、脚本),建议使用个人访问令牌替代 JWT。PAT 过期时间更长,可以设置作用域。
详情请参见 API 令牌 文档。