mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6192] [CLOSED] feat(auth): Add OIDC/OAuth2 login with admin + self-service tiers #6154
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6154
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6192
Author: @CRASH-Tech
Created: 8/9/2026
Status: ❌ Closed
Base:
main← Head:add-oauth2📝 Commits (5)
16cb959Add oauth2 auth04ed06fadd oauth2 clients background inbounds sync05972b2Allow configure oauth via ui898cc4cadd oauth2 admis as a user5f4b63aAdd user flow provision📊 Changes
62 files changed (+6327 additions, -523 deletions)
View changed files
📝
README.ar_EG.md(+20 -0)📝
README.es_ES.md(+20 -0)📝
README.fa_IR.md(+20 -0)📝
README.md(+20 -0)📝
README.ru_RU.md(+20 -0)📝
README.tr_TR.md(+20 -0)📝
README.zh_CN.md(+20 -0)📝
docker-compose.yml(+15 -0)📝
docs/public/openapi.json(+2092 -486)➕
frontend/cabinet.html(+14 -0)📝
frontend/public/openapi.json(+277 -0)➕
frontend/src/entries/cabinet.tsx(+31 -0)📝
frontend/src/generated/examples.ts(+32 -0)📝
frontend/src/generated/schemas.ts(+138 -0)📝
frontend/src/generated/types.ts(+32 -0)📝
frontend/src/generated/zod.ts(+32 -0)📝
frontend/src/models/setting.ts(+20 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+24 -0)➕
frontend/src/pages/cabinet/CabinetPage.css(+27 -0)➕
frontend/src/pages/cabinet/CabinetPage.tsx(+206 -0)...and 42 more files
📄 Description
feat(auth): OIDC/OAuth2 login with admin + self-service tiers
Summary
Adds single sign-on through any OpenID Connect provider (Keycloak, Authentik,
Authelia, Google, Azure AD, Okta, …). It can be configured declaratively via
XUI_OAUTH_*environment variables, from the panel settings UI, or both —env values take precedence and lock the matching UI fields read-only.
A group claim in the ID token maps each caller to one of two tiers:
first user (no per-admin data, so no new rows / migration).
inbound(s) whose remark matches the configured list, and the user lands in a
self-service cabinet showing only their own connection: subscription URL,
share links with protocol/transport badges, QR codes, and traffic/expiry.
How it works
audience and nonce are verified before a session is opened.
client subId live in the session — no DB schema change / migration.
XUI_OAUTH_*(priority) over stored values. An env-pinned field is shown read-only in the UI
with its live value; the client secret is never echoed (only a "configured"
flag). Server-side, env-locked fields cannot be changed through the API. The
enable toggle is auto-on and locked when the issuer + client id come from env.
ClientService.Create(runtime-safe, the LDAP-sync path),so multi-node deployments are handled. It is idempotent and reconciling: on
later logins an existing client is attached to any newly matching inbound (same
subId/limits, no reset).
users, so a new matching inbound reaches them without a re-login. It only
attaches — never deletes or disables.
Configuration
Every knob is available as a
XUI_OAUTH_*env var and as a panel setting:XUI_OAUTH_ISSUER/_CLIENT_ID/_CLIENT_SECRETXUI_OAUTH_REDIRECT_URLXUI_OAUTH_ADMIN_GROUPXUI_OAUTH_USER_GROUPXUI_OAUTH_USER_INBOUND_REMARKXUI_OAUTH_USER_TOTAL_GB/_EXPIRY_DAYS/_LIMIT_IP0= unlimited/neverXUI_OAUTH_SCOPES/_GROUPS_CLAIM/_USERNAME_CLAIMopenid,profile,email,groups/groups/emailChanges
internal/config/oauth.go;internal/util/oauth/(go-oidc/oauth2wrapper: discovery, auth URL, code exchange, claim extraction); routes
GET /oauth/login,/oauth/callback,/getOAuthEnable,/cabinet/,/cabinet/data; session role/subid/flow helpers;OAuthProvisionService(provision + reconcile) and
OAuthSyncJob; role gating incheckLogin.Settings:
Oauth*fields onAllSetting,HasOauthClientSecret+OauthEnvLockedonAllSettingView,GetEffectiveOAuthConfig/OAuthEnvLocks/OAuthEnabledEffective/enforceOauthEnvLocks. The OIDCprovider is cached by a config signature so UI edits apply without a restart.
cabinetbundle reusing the subscription page's link/QR components; an "OIDC"section in Settings mirroring LDAP, with env-pinned fields disabled.
github.com/coreos/go-oidc/v3,golang.org/x/oauth2.endpoints.tsXUI_OAUTH_*documented in all 7 README translations;a commented example in
docker-compose.yml.Testing
JWKS + signed ID token, incl. nonce/audience rejection); role mapping;
provisioning (create/reuse, multi-remark, attach-on-new-inbound); batch
reconcile; effective-config env precedence, env locks, enable resolution and
the server-side lock enforcement; a regression test for callback host
resolution (see notes).
go build ./...,golangci-lint(0 issues), gofumpt, route-registry contract— all green.
Notes
Hostheader (with port) produced amalformed
@[host:port]:443URL; the callback now uses the sub server's ownhost resolution.
SubPage and cabinet — such links are too large to scan; use the subscription QR.
user pool (no schema marker), so a manually-added client on such an inbound is
also mirrored across the pool. A
Group/Commentmarker could scope this morestrictly if desired.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.