Skip to content

feat: align NewAPI identity with Account Center subjects - #6863

Closed
AidenNovak wants to merge 4 commits into
QuantumNous:mainfrom
AidenNovak:feat/account-center-identity
Closed

feat: align NewAPI identity with Account Center subjects#6863
AidenNovak wants to merge 4 commits into
QuantumNous:mainfrom
AidenNovak:feat/account-center-identity

Conversation

@AidenNovak

@AidenNovak AidenNovak commented Aug 15, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

This change was AI-assisted. I reviewed the Account Center identity contract, the three commits, and the local CI-equivalent test run before opening the PR.

📝 变更描述 / Description

NewAPI now plugs into the shared Account Center identity without copying the Vultr login shell.

Account Center already merges email / Google / GitHub onto one OIDC sub. These commits make NewAPI consume that subject as the only customer key, and add an optional signed quota overview so Account Center can display the API wallet.

  1. Persist OIDC subjects as digest-backed exact claims, including startup backfill from users.oidc_id.
  2. Resolve OIDC login and bind through that claim. Same sub is the same NewAPI user; matching email on a different local user is a conflict, not a merge.
  3. Add POST /api/internal/account/overview (HMAC) and GET /api/account-center (HTTPS redirect). Both stay closed unless configured.

Existing GitHub/Discord/password login paths are unchanged. OIDC PKCE / portal-only login UX is intentionally not ported.

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Align NewAPI with the Account Center Meimaobing Subject contract.

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

Each commit was written so it can land independently:

  1. feat(identity): claim OIDC subjects as exact opaque identities
  2. feat(oauth): resolve OIDC users by exact subject claims
  3. feat(account-center): expose a signed API wallet overview

Local verification matching this repo's CI backend job:

GOWORK=off go vet ./controller/ ./model/ ./router/
make test

Both succeeded. Frontend files were not changed; CI typecheck should remain a no-op for this diff.

Test plan

  • Confirm make test on CI.
  • Confirm frontend typecheck on CI.
  • First OIDC login with a new sub creates one NewAPI user and a claim row.
  • Repeat login with the same sub returns the same user even if the email claim changed.
  • OIDC login with an email already owned by another NewAPI user is rejected (no merge).
  • With HMAC secret unset, POST /api/internal/account/overview returns 404.
  • With HMAC secret set, Account Center can read quota by sub and does not see keys or session data.

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Added optional Account Center integration with secure HMAC-authenticated account overviews and HTTPS redirects.
    • Added OIDC identity binding and login support based on exact identity subjects.
    • Added configuration options for Account Center security and public URL settings.
  • Bug Fixes

    • Improved handling of duplicate, deleted, ambiguous, and case-sensitive external identities.
    • Prevented account data from being exposed for unregistered identities.
  • Chores

    • Improved CI and release workflow safeguards and status reporting.

AidenNovak and others added 4 commits August 15, 2026 12:36
* Wire NewAPI CI to this fork and keep upstream publish workflows off.

The stock PR Check workflow closes AI-looking PRs, and Docker jobs push to the official calciumion image. Neither belongs on this freeze.

* Drop bun test from the required frontend gate on this freeze.

rc.24's web tests mix node:test describe() with bun test, which fails on the pinned Bun and would block every product PR.

---------

Co-authored-by: AidenNovak <>
Account Center treats issuer+sub as the only cross-product user key.
Store those subjects in digest-backed claims so MySQL collation cannot
merge distinct OIDC ids, and backfill existing oidc_id rows on startup.

Co-authored-by: Cursor <cursoragent@cursor.com>
Account Center already merges email/Google/GitHub onto one sub. NewAPI
now follows that subject on login and bind, and refuses to attach an
OIDC identity to a different local user just because the emails match.

Co-authored-by: Cursor <cursoragent@cursor.com>
Account Center needs a subject-keyed quota display without a dashboard
session. Keep the HMAC endpoint and HTTPS redirect disabled until their
secrets are configured so default deployments stay closed.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5f354ea1-4d68-4838-a856-86c9b9f28a39

📥 Commits

Reviewing files that changed from the base of the PR and between 7d09c69 and 1b4b704.

📒 Files selected for processing (16)
  • .env.example
  • .github/workflows/ci.yml
  • .github/workflows/docker-build.yml
  • .github/workflows/docker-image-branch.yml
  • .github/workflows/electron-build.yml
  • .github/workflows/pr-check.yml
  • .github/workflows/release.yml
  • controller/account_center.go
  • controller/account_center_test.go
  • controller/oauth.go
  • controller/oauth_oidc_identity_test.go
  • model/external_identity_claim.go
  • model/external_identity_claim_test.go
  • model/main.go
  • model/user.go
  • router/api-router.go

Walkthrough

This change adds Account Center configuration, redirect and HMAC-authenticated overview endpoints, exact OIDC identity claims, transactional OIDC login and binding, related tests, and repository-scoped CI and release workflow conditions.

Changes

Account Center and OIDC identity integration

Layer / File(s) Summary
External identity claims and OIDC ownership
model/external_identity_claim.go, model/external_identity_claim_test.go, model/main.go, model/user.go
OIDC claims now use validated exact subjects and SHA-256 digests. Schema migration, legacy claim initialization, lookup, ownership checks, and binding release support the new model.
Transactional OIDC login and binding
controller/oauth.go, controller/oauth_oidc_identity_test.go
OIDC login and binding use exact subjects, atomic creation, duplicate-claim handling, and shared OAuth user initialization.
Account Center configuration and API
.env.example, controller/account_center.go, controller/account_center_test.go, router/api-router.go
The API adds a configured HTTPS redirect and a signed overview endpoint with request validation and OIDC-bound account data.

Workflow execution guards

Layer / File(s) Summary
Repository-scoped CI and release execution
.github/workflows/ci.yml, .github/workflows/docker-build.yml, .github/workflows/docker-image-branch.yml, .github/workflows/electron-build.yml, .github/workflows/pr-check.yml, .github/workflows/release.yml
CI runs on pushes to main and reports backend and frontend results. Build and release jobs run only in QuantumNous/new-api.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AccountCenter
  participant API
  participant GetAccountCenterOverview
  participant ExternalIdentityClaim
  AccountCenter->>API: POST /internal/account/overview
  API->>GetAccountCenterOverview: forward bounded request
  GetAccountCenterOverview->>ExternalIdentityClaim: verify signature and resolve OIDC subject
  ExternalIdentityClaim-->>GetAccountCenterOverview: return matching user
  GetAccountCenterOverview-->>AccountCenter: return account metrics
Loading

Possibly related PRs

  • QuantumNous/new-api#6329: Introduces the OIDC flow and external identity-claim infrastructure extended by this change.

Suggested reviewers: wans10

Poem

A rabbit signs requests beneath the moon,
OIDC claims now match subjects true.
Account Center opens with a key,
Safe redirects point where they should be.
CI hops on main, workflows stay in tune.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (ai_padded_prose). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

@AidenNovak

Copy link
Copy Markdown
Author

Closing: this was opened against upstream by mistake. The change belongs on the AidenNovak/newapi-custom fork (Account Center identity wiring), not QuantumNous/new-api.

@AidenNovak AidenNovak closed this Aug 15, 2026
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