feat(cloud): complete OpenCSG SSO login automatically on the lite side - #142
Merged
Conversation
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.
# Conflicts: # web/src/pages/Settings.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
让 lite 端「登录」体验达到一键自动完成:用户在设置页点击登录后,系统浏览器打开 OpenCSG 官网登录页,登录成功后无需任何手动复制 token 的操作,lite 自动完成登录。
这套流程依赖 starhub-server 侧的 SSO 回调改造,见关联 MR:
对接约定
state从casdoor改为lite;server 据此识别 lite 客户端,取/建名为csglite的 git 应用 token(不产生计费)。http://127.0.0.1:11437/api/cloud/auth/callback?token=...&portal_url=...&jwt=...,由 lite 侧车进程上的独立 loopback listener 接收。改动内容
DefaultAuthCallbackAddr = "127.0.0.1:11437"及Config.AuthCallbackAddr字段。DefaultLoginURL的state=casdoor→state=lite。GET /api/cloud/auth/callback:持久化 query 里的token并返回一个简单 HTML 确认页。saveCloudAccessToken供 token 保存与回调共用;shutdown 时一并关闭该 http server。GET /api/cloud/auth,最长 5 分钟,一旦authenticated && user即停,UI 自动切到已登录状态。internal/server/static/openapi/local-api.json。TestHandleCloudAuthCallback、TestHandleCloudAuthCallbackMissingToken。验证
go build ./...通过go test ./internal/server/ -count=1通过cd web && npm run build通过说明
state=lite约定;lite 端已兼容,部署先后顺序不影响编译。