mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 17:47:27 +00:00
216 lines
6.1 KiB
Text
216 lines
6.1 KiB
Text
---
|
||
title: LobeHub 身份验证服务设置
|
||
description: 了解如何配置 LobeHub 的身份验证服务环境变量,包括 Better Auth、OAuth SSO 等。
|
||
tags:
|
||
- LobeHub
|
||
- 身份验证服务
|
||
- Better Auth
|
||
- 单点登录
|
||
---
|
||
|
||
# 身份验证服务
|
||
|
||
LobeHub 在部署时提供了完善的身份验证服务能力,以下是相关的环境变量,你可以使用这些环境变量轻松定义需要在 LobeHub 中开启的身份验证服务。
|
||
|
||
## Better Auth
|
||
|
||
### 通用设置
|
||
|
||
#### `AUTH_SECRET`
|
||
|
||
- 类型:必选
|
||
- 描述:用于加密会话令牌的密钥。使用以下命令生成:`openssl rand -base64 32`
|
||
- 默认值:`-`
|
||
- 示例:`Tfhi2t2pelSMEA8eaV61KaqPNEndFFdMIxDaJnS1CUI=`
|
||
|
||
#### `AUTH_EMAIL_VERIFICATION`
|
||
|
||
- 类型:可选
|
||
- 描述:设置为 `1` 以要求用户在登录前验证邮箱。用户注册后必须验证邮箱地址。
|
||
- 默认值:`0`
|
||
- 示例:`1`
|
||
|
||
#### `AUTH_SSO_PROVIDERS`
|
||
|
||
- 类型:可选
|
||
- 描述:启用的 SSO 提供商列表,以逗号分隔。顺序决定了登录页面上提供商的显示顺序。
|
||
- 默认值:`-`
|
||
- 示例:`google,github,microsoft,cognito`
|
||
|
||
#### `AUTH_ALLOWED_EMAILS`
|
||
|
||
- 类型:可选
|
||
- 描述:允许注册的邮箱或域名白名单,以逗号分隔。支持完整邮箱地址(如 `user@example.com`)或域名(如 `example.com`)。留空表示允许所有邮箱。
|
||
- 默认值:`-`
|
||
- 示例:`example.com,admin@other.com`
|
||
|
||
#### `AUTH_DISABLE_EMAIL_PASSWORD`
|
||
|
||
- 类型:可选
|
||
- 描述:设置为 `1` 以禁用邮箱密码登录,强制用户使用 SSO 登录。启用后,登录页面将隐藏邮箱输入框,注册页面将重定向到登录页。
|
||
- 默认值:`0`
|
||
- 示例:`1`
|
||
|
||
#### `JWKS_KEY`
|
||
|
||
- 类型:必选
|
||
- 描述:用于签名和验证 JWT 的 JWKS(JSON Web Key Set)密钥。用于 OIDC JWT token 签名和内部服务调用认证 token。必须是包含 RS256 RSA 密钥对的 JWKS JSON 字符串。
|
||
- 默认值:`-`
|
||
|
||
<GenerateJWKSKey />
|
||
|
||
#### `INTERNAL_JWT_EXPIRATION`
|
||
|
||
- 类型:可选
|
||
- 描述:内部 JWT 令牌的过期时间,用于 lambda → async 调用。格式:数字后跟单位(s = 秒,m = 分钟,h = 小时)。为了安全性应尽可能短,但需要足够长以应对网络延迟和服务器处理时间。
|
||
- 默认值:`30s`
|
||
- 示例:`30s`、`1m`、`1h`
|
||
|
||
### 邮件服务(SMTP)
|
||
|
||
启用邮箱验证和密码重置功能需要配置以下设置。
|
||
|
||
#### `SMTP_HOST`
|
||
|
||
- 类型:必选(用于邮件功能)
|
||
- 描述:SMTP 服务器主机名。
|
||
- 默认值:`-`
|
||
- 示例:`smtp.gmail.com`
|
||
|
||
#### `SMTP_PORT`
|
||
|
||
- 类型:必选(用于邮件功能)
|
||
- 描述:SMTP 服务器端口。TLS 通常为 `587`,SSL 为 `465`。
|
||
- 默认值:`-`
|
||
- 示例:`587`
|
||
|
||
#### `SMTP_SECURE`
|
||
|
||
- 类型:可选
|
||
- 描述:是否使用安全连接。端口 465(SSL)设置为 `true`,端口 587(TLS)设置为 `false`。
|
||
- 默认值:`false`
|
||
- 示例:`false`
|
||
|
||
#### `SMTP_USER`
|
||
|
||
- 类型:必选(用于邮件功能)
|
||
- 描述:SMTP 认证用户名,通常是您的邮箱地址。
|
||
- 默认值:`-`
|
||
- 示例:`your-email@example.com`
|
||
|
||
#### `SMTP_PASS`
|
||
|
||
- 类型:必选(用于邮件功能)
|
||
- 描述:SMTP 认证密码。Gmail 需使用应用专用密码。
|
||
- 默认值:`-`
|
||
- 示例:`your-app-specific-password`
|
||
|
||
#### `SMTP_FROM`
|
||
|
||
- 类型:可选
|
||
- 描述:发件人邮箱地址。AWS SES 等服务需要此配置(因为 `SMTP_USER` 不是有效邮箱地址)。若未设置,默认使用 `SMTP_USER`。
|
||
- 默认值:`SMTP_USER` 的值
|
||
- 示例:`noreply@example.com`
|
||
|
||
### Google
|
||
|
||
#### `AUTH_GOOGLE_ID`
|
||
|
||
- 类型:必选
|
||
- 描述:Google OAuth 应用的 Client ID。在 [Google Cloud Console](https://console.cloud.google.com/apis/credentials) 获取。
|
||
- 默认值:`-`
|
||
- 示例:`123456789.apps.googleusercontent.com`
|
||
|
||
#### `AUTH_GOOGLE_SECRET`
|
||
|
||
- 类型:必选
|
||
- 描述:Google OAuth 应用的 Client Secret。
|
||
- 默认值:`-`
|
||
- 示例:`GOCSPX-xxxxxxxxxxxxxxxxxxxx`
|
||
|
||
### GitHub
|
||
|
||
#### `AUTH_GITHUB_ID`
|
||
|
||
- 类型:必选
|
||
- 描述:GitHub OAuth 应用的 Client ID。在 [GitHub Developer Settings](https://github.com/settings/developers) 获取。
|
||
- 默认值:`-`
|
||
- 示例:`Ov23xxxxxxxxxxxxx`
|
||
|
||
#### `AUTH_GITHUB_SECRET`
|
||
|
||
- 类型:必选
|
||
- 描述:GitHub OAuth 应用的 Client Secret。
|
||
- 默认值:`-`
|
||
- 示例:`xxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
|
||
|
||
### Microsoft
|
||
|
||
#### `AUTH_MICROSOFT_ID`
|
||
|
||
- 类型:必选
|
||
- 描述:Microsoft Entra ID(Azure AD)应用的 Client ID。在 [Azure 门户](https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade) 获取。
|
||
- 默认值:`-`
|
||
- 示例:`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
|
||
|
||
#### `AUTH_MICROSOFT_SECRET`
|
||
|
||
- 类型:必选
|
||
- 描述:Microsoft Entra ID 应用的 Client Secret。
|
||
- 默认值:`-`
|
||
- 示例:`xxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
|
||
|
||
### AWS Cognito
|
||
|
||
#### `AUTH_COGNITO_ID`
|
||
|
||
- 类型:必选
|
||
- 描述:AWS Cognito 用户池应用客户端的 Client ID。在 [AWS Cognito 控制台](https://console.aws.amazon.com/cognito) 获取。
|
||
- 默认值:`-`
|
||
- 示例:`xxxxxxxxxxxxxxxxxxxxx`
|
||
|
||
#### `AUTH_COGNITO_SECRET`
|
||
|
||
- 类型:必选
|
||
- 描述:AWS Cognito 应用客户端的 Client Secret。
|
||
- 默认值:`-`
|
||
- 示例:`xxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
|
||
|
||
#### `AUTH_COGNITO_ISSUER`
|
||
|
||
- 类型:必选
|
||
- 描述:Cognito 用户池的颁发者 URL。格式:`https://cognito-idp.{region}.amazonaws.com/{userPoolId}`
|
||
- 默认值:`-`
|
||
- 示例:`https://cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxxxxx`
|
||
|
||
### 飞书
|
||
|
||
#### `AUTH_FEISHU_APP_ID`
|
||
|
||
- 类型:必选
|
||
- 描述:飞书应用的 App ID。在 [飞书开放平台](https://open.feishu.cn/app) 获取。
|
||
- 默认值:`-`
|
||
- 示例:`cli_xxxxxxxxxxxxxxxx`
|
||
|
||
#### `AUTH_FEISHU_APP_SECRET`
|
||
|
||
- 类型:必选
|
||
- 描述:飞书应用的 App Secret。
|
||
- 默认值:`-`
|
||
- 示例:`xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
|
||
|
||
### 微信
|
||
|
||
#### `AUTH_WECHAT_ID`
|
||
|
||
- 类型:必选
|
||
- 描述:微信开放平台应用的 App ID。在 [微信开放平台](https://open.weixin.qq.com/) 获取。
|
||
- 默认值:`-`
|
||
- 示例:`wxxxxxxxxxxxxxxxxxxx`
|
||
|
||
#### `AUTH_WECHAT_SECRET`
|
||
|
||
- 类型:必选
|
||
- 描述:微信应用的 App Secret。
|
||
- 默认值:`-`
|
||
- 示例:`xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
|