Skip to content

feat(auth): 支持 OIDC 并映射到本地用户 - #199

Open
hi-pengbo wants to merge 1 commit into
MoonTechLab:mainfrom
hi-pengbo:main
Open

feat(auth): 支持 OIDC 并映射到本地用户#199
hi-pengbo wants to merge 1 commit into
MoonTechLab:mainfrom
hi-pengbo:main

Conversation

@hi-pengbo

Copy link
Copy Markdown

背景

LunaTV 只有本地用户名/密码登录,无法对接 Authelia / Authentik / Keycloak 等身份提供方。这次补上标准 OIDC,登录后仍走现有用户体系(角色、收藏、播放记录、用户组不变)。

改动

  • 新增 Authorization Code + PKCE 登录流:/api/oidc/login/api/oidc/callback
  • OIDC 身份映射到现有用户:优先按 sub 绑定,其次按用户名;可自动建号;用户名等于 USERNAME 时按站长登录
  • 登录页增加 OIDC 按钮,支持隐藏密码登录
  • 管理面板为 OIDC 用户显示标记
  • 抽出共享 auth cookie 签发逻辑,密码登录行为保持不变
  • 适配反向代理 / HTTPS / 非标准端口:固定回调地址,并按发现文档选择 client_secret_post(兼容 Authelia 将单个 client 固定为 post 的配置)
  • 补充环境变量说明与单测

使用

需要 redis / kvrocks / upstash 多用户存储,不支持 localstorage

OIDC_ISSUER=https://auth.example.com
OIDC_CLIENT_ID=moontv
OIDC_CLIENT_SECRET=your_plaintext_secret
OIDC_REDIRECT_URI=https://tv.example.com/api/oidc/callback
OIDC_CLIENT_AUTH=post
SITE_BASE=https://tv.example.com

身份提供方登记的回调必须与 OIDC_REDIRECT_URI 完全一致。

说明

OIDC 只负责认证,不替代 Redis。账号密码登录默认可继续使用,设置 OIDC_DISABLE_PASSWORD=true 可关闭。

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