forked from wangziqi/gongxue-base
fix: default tenant PNVS secrets to sms scope
This commit is contained in:
@@ -379,6 +379,17 @@ function secretRef(scope: SecretScope, secretKey: string) {
|
||||
return `app_private.tenant_secrets:${scope}:${secretKey}`;
|
||||
}
|
||||
|
||||
function defaultAuthSecretScope(provider: string): SecretScope {
|
||||
const normalized = provider.toLowerCase().replace(/[_\s]/g, '-');
|
||||
if (
|
||||
normalized.includes('sms') ||
|
||||
normalized === 'aliyun' ||
|
||||
normalized === 'aliyun-pnvs' ||
|
||||
normalized === 'tencent'
|
||||
) return 'sms';
|
||||
return 'oauth';
|
||||
}
|
||||
|
||||
function parseSecretScope(value: unknown, fallback: SecretScope): SecretScope {
|
||||
const candidate = (nullableString(value) || fallback) as SecretScope;
|
||||
if (!SECRET_SCOPES.has(candidate)) {
|
||||
@@ -1386,7 +1397,7 @@ export async function upsertAuthProviderRoute(ctx: RequestContext) {
|
||||
requireTenantPermission(auth, 'tenant:auth:write');
|
||||
const body = await readJsonBody(ctx);
|
||||
const provider = requiredString(body, 'provider');
|
||||
const fallbackScope = provider.toLowerCase().includes('sms') ? 'sms' : 'oauth';
|
||||
const fallbackScope = defaultAuthSecretScope(provider);
|
||||
const secretPayload = parseSecretPayload(body, fallbackScope, provider, provider);
|
||||
const configPublic = objectValue(body.configPublic);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user