fix: default tenant PNVS secrets to sms scope

This commit is contained in:
Codex
2026-07-03 22:54:36 +08:00
parent 9f4fd6530a
commit cd0f465689
3 changed files with 39 additions and 1 deletions

View File

@@ -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);