HiBerNET 门户 / SSO API 文档
门户负责两件事:展示服务入口,以及作为 SSO 登录终结端点。 本文档覆盖门户会话、SSO 登录交接与本地轮询协议;文档系统的查询 API 另见「文档 API」章节(随文档中心部署启用)。
0. 基础信息
- Base URL
https://hbns.hibernet.top- SSO Issuer
https://sso.hibernet.top/oidc- Client ID
c22FUljpLTZBPGLo- 认证方式
- Client Secret JWT(HS256,client_assertion)
- 授权类型
- authorization_code、refresh_token
- 允许组
- auth-admin、hbns-user、hbns-admin
- 响应类型
- code(PKCE S256)
1. 登录流转
浏览器 / 启动器
│ 打开 https://hbns.hibernet.top/sso-endpoint
▼
/sso-endpoint/start ──302──▶ https://sso.hibernet.top/oidc/auth?response_type=code&...
│ 用户完成登录
▼
/sso-endpoint/callback?code=...&state=...
│ 服务端用 client_secret_jwt 换 token,拉 userinfo,写门户会话
├─▶ 本地模式:302 到 http://localhost:29121/auth-response?handoff=...&state=...
│ 本地应用 GET /sso-endpoint/handoff?id=... 兑换令牌(180 秒,一次性)
└─▶ 门户模式:302 回 https://hbns.hibernet.top/account?login=ok2. 端点
GET /sso-endpoint/start
发起登录。生成 state / nonce / PKCE,写入 HttpOnly 事务 Cookie,然后跳转 IdP。
- redirect
- 可选;仅允许
http://localhost:*/http://127.0.0.1:*, 默认http://localhost:29121/auth-response。 - next
- 可选;站内路径(以
/开头),登录后留在门户,如?next=/account。
GET /sso-endpoint/callback
IdP 回调(内部使用)。校验 state 与事务 Cookie,换取令牌并终结登录。
GET /sso-endpoint/handoff?id=…
兑换一次性 handoff。票据为 AES-256-GCM 加密,180 秒过期;响应不缓存。
GET https://hbns.hibernet.top/sso-endpoint/handoff?id=...
{
"state": "…",
"user": { "sub": "…", "name": "…", "email": "…", "groups": ["hbns-user"] },
"tokens": {
"access_token": "…",
"id_token": "…",
"refresh_token": "…",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "openid profile email groups offline_access"
},
"expires_at": 1799999999
}错误:400 missing_id、410 invalid_or_expired。
GET /sso-endpoint/status?state=…
本地轮询用。登录完成后返回 complete 与 handoff;未完成返回 pending。
GET https://hbns.hibernet.top/sso-endpoint/status?state=...
{ "state": "…", "status": "pending" }
{ "state": "…", "status": "complete", "handoff": "…" }说明:轮询状态保存在单实例内存中,适合本地开发或单实例部署;Vercel 多实例下建议使用重定向交接(更可靠)。
GET /sso-endpoint/logout
清除门户会话,跳转 IdP end_session_endpoint,并回跳http://localhost:29122/logout-callback。
3. 门户 API
GET /api/session
返回当前门户会话(Cookie 认证)。未登录返回 401。
GET https://hbns.hibernet.top/api/session
{
"authenticated": true,
"user": { "sub": "…", "groups": ["hbns-user"], "name": "…" },
"expires_at": 1799999999
}4. 错误码
- server_misconfigured
- 服务端缺少
SSO_CLIENT_SECRET。 - missing_code_or_state
- 回调缺少 code 或 state。
- invalid_state
- 事务过期或 state 不匹配(可能是重复打开登录页)。
- token_exchange_failed
- IdP 拒绝换票(client_assertion、redirect_uri、code 失效等)。
- userinfo_failed
- access_token 无法读取用户信息。
- access_denied
- 账号不属于 auth-admin / hbns-user / hbns-admin。
5. 文档 API(随文档中心启用)
文档中心为每个账号签发查询令牌,令牌继承创建者权限;请求时使用Authorization: Bearer <token>。未授权文档不会出现在列表或搜索结果中。 部署完成后本节会补充实际端点与示例。