feat(auth): aggregate OAuth 支持环境变量回退配置,默认 LOGIN_TYPE=wx
- oauth-strategies.ts: loadAggregateSettings() DB 未配置时回退读取 process.env.AGGREGATE_OAUTH_*,自动启用 - .env.example: AGGREGATE_OAUTH_LOGIN_TYPE 默认改为 wx,补充 auxx.cn 示例注释
This commit is contained in:
@@ -270,7 +270,33 @@ async function loadAggregateSettings() {
|
||||
.from(systemSettings)
|
||||
.orderBy(asc(systemSettings.id))
|
||||
.limit(1)
|
||||
return row[0] ?? null
|
||||
const base = row[0] ?? null
|
||||
const envAppId = process.env.AGGREGATE_OAUTH_APP_ID
|
||||
const envAppKey = process.env.AGGREGATE_OAUTH_APP_KEY
|
||||
const envLoginType = process.env.AGGREGATE_OAUTH_LOGIN_TYPE
|
||||
const envEndpoint = process.env.AGGREGATE_OAUTH_ENDPOINT
|
||||
const hasEnvConfig = !!(envAppId && envAppKey && envEndpoint)
|
||||
const dbEnabled = base?.aggregateOAuthEnabled
|
||||
const dbHasConfig = !!(
|
||||
base?.aggregateOAuthAppId &&
|
||||
base?.aggregateOAuthAppKey &&
|
||||
base?.aggregateOAuthEndpoint
|
||||
)
|
||||
const enabled = Boolean(dbEnabled ?? hasEnvConfig)
|
||||
const appId = (base?.aggregateOAuthAppId || envAppId || '') as string
|
||||
const appKey = (base?.aggregateOAuthAppKey || envAppKey || '') as string
|
||||
const loginType = ((base?.aggregateOAuthLoginType as string) || envLoginType || '') as string
|
||||
const endpoint = ((base?.aggregateOAuthEndpoint as string) || envEndpoint || '') as string
|
||||
|
||||
return {
|
||||
aggregateOAuthEnabled: enabled && !!(appId && appKey && endpoint),
|
||||
aggregateOAuthAppId: appId,
|
||||
aggregateOAuthAppKey: appKey,
|
||||
aggregateOAuthLoginType: loginType,
|
||||
aggregateOAuthEndpoint: endpoint,
|
||||
_dbHasConfig: dbHasConfig,
|
||||
_hasEnvConfig: hasEnvConfig
|
||||
} as any
|
||||
}
|
||||
|
||||
function normalizeEndpoint(endpoint: string): string {
|
||||
|
||||
Reference in New Issue
Block a user