Skip to content

feat(cloud): complete OpenCSG SSO login automatically on the lite side - #142

Merged
ganisback merged 3 commits into
mainfrom
fix/lite-sso-auto-login
Sep 5, 2026
Merged

feat(cloud): complete OpenCSG SSO login automatically on the lite side#142
ganisback merged 3 commits into
mainfrom
fix/lite-sso-auto-login

Conversation

@ganisback

Copy link
Copy Markdown
Collaborator

Summary

让 lite 端「登录」体验达到一键自动完成:用户在设置页点击登录后,系统浏览器打开 OpenCSG 官网登录页,登录成功后无需任何手动复制 token 的操作,lite 自动完成登录。

这套流程依赖 starhub-server 侧的 SSO 回调改造,见关联 MR:

对接约定

  • 登录授权 statecasdoor 改为 lite;server 据此识别 lite 客户端,取/建名为 csglite 的 git 应用 token(不产生计费)。
  • server 登录成功后重定向到 http://127.0.0.1:11437/api/cloud/auth/callback?token=...&portal_url=...&jwt=...,由 lite 侧车进程上的独立 loopback listener 接收。

改动内容

  1. config:新增 DefaultAuthCallbackAddr = "127.0.0.1:11437"Config.AuthCallbackAddr 字段。
  2. cloudDefaultLoginURLstate=casdoorstate=lite
  3. server
    • 启动一个专用循环回环 listener(11437),失败仅告警不退出,避免与主 UI 随机端口、外部推理 11436 冲突。
    • 新增 GET /api/cloud/auth/callback:持久化 query 里的 token 并返回一个简单 HTML 确认页。
    • 抽取 saveCloudAccessToken 供 token 保存与回调共用;shutdown 时一并关闭该 http server。
  4. web:点击登录按钮打开官网后,前端每 1.5s 轮询 GET /api/cloud/auth,最长 5 分钟,一旦 authenticated && user 即停,UI 自动切到已登录状态。
  5. OpenAPI:补充回调端点文档并同步 internal/server/static/openapi/local-api.json
  6. 测试:新增 TestHandleCloudAuthCallbackTestHandleCloudAuthCallbackMissingToken

验证

  • go build ./... 通过
  • go test ./internal/server/ -count=1 通过
  • cd web && npm run build 通过

说明

  • 本 MR 不改 csglite-client(Tauri 壳):登录交互全部在 csglite web 内,浏览器回调打到侧车进程的 11437,client 不参与登录流程。
  • 与 starhub-server #2977 使用同一 state=lite 约定;lite 端已兼容,部署先后顺序不影响编译。

Add an SSO callback flow so that after a user clicks "Sign in" in the
csglite settings page, the OpenCSG web login can hand the access token
straight back to the lite process without any further manual step.

- change the login authorization state from casdoor to lite
- start a dedicated loopback callback listener on 127.0.0.1:11437
- add GET /api/cloud/auth/callback to persist the returned token and
  render a small confirmation page
- poll the cloud auth status in the web UI after opening the login page
- document the new endpoint in the OpenAPI spec and its static copy

Closes #135
Depends on https://git-devops.opencsg.com/product/starhub/starhub-server/-/merge_requests/2977
Replace the manual Access Token entry flow in the Chat, AI Apps,
Image Generation, and Settings dialogs with polling: clicking
Open Login opens SSO and polls cloud auth status until the callback
persists the token, then refreshes the model lists. Removes the
now-unused token input UI and i18n strings.
@ganisback
ganisback merged commit 88c2d5d into main Sep 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

设置页面里的《打开登陆》点击登陆了但不返回原页面

1 participant