Skip to content

Commit 9aad3de

Browse files
authored
refactor: Refactor authentication method based on presence of client credentials (#5)
- Refactor authentication method based on presence of client credentials in payload.
1 parent 5332a53 commit 9aad3de

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

web/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,9 @@ <h1 class="logo"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stro
17411741
try { clientData = JSON.parse(clientJson); } catch { alert(t('local.clientInvalid')); return; }
17421742
if (!clientData.clientId || !clientData.clientSecret) { alert(t('local.clientSecretMissing')); return; }
17431743
}
1744-
const payload = { refreshToken: tokenData.refreshToken, accessToken: tokenData.accessToken || '', clientId: clientData?.clientId || '', clientSecret: clientData?.clientSecret || '', authMethod: isSocial ? 'social' : 'idc', provider: provider };
1744+
// 根据是否有 clientData 判断认证方式
1745+
const authMethod = clientData ? 'idc' : 'social';
1746+
const payload = { refreshToken: tokenData.refreshToken, accessToken: tokenData.accessToken || '', clientId: clientData?.clientId || '', clientSecret: clientData?.clientSecret || '', authMethod: authMethod, provider: provider };
17451747
const res = await fetch('/admin/api/auth/credentials', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Admin-Password': password }, body: JSON.stringify(payload) });
17461748
const d = await res.json();
17471749
if (d.success) { closeModal(); loadAccounts(); loadStats(); alert(t('local.importSuccess') + ': ' + (d.account?.email || d.account?.id)); }
@@ -1754,9 +1756,10 @@ <h1 class="logo"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stro
17541756
let success = 0, failed = 0, errors = [];
17551757
for (const item of items) {
17561758
if (!item.refreshToken) { failed++; errors.push('missing refreshToken'); continue; }
1757-
const provider = (item.provider || 'BuilderId').toLowerCase();
1758-
const isSocial = provider === 'google' || provider === 'github' || provider === 'builderid';
1759-
const payload = { refreshToken: item.refreshToken, clientId: item.clientId || '', clientSecret: item.clientSecret || '', authMethod: isSocial ? 'social' : 'idc', provider: item.provider || 'BuilderId' };
1759+
// 根据是否包含 clientId/clientSecret 判断认证方式
1760+
const hasClientCredentials = !!(item.clientId && item.clientSecret);
1761+
const authMethod = hasClientCredentials ? 'idc' : 'social';
1762+
const payload = { refreshToken: item.refreshToken, clientId: item.clientId || '', clientSecret: item.clientSecret || '', authMethod: authMethod, provider: item.provider || 'BuilderId' };
17601763
try {
17611764
const res = await fetch('/admin/api/auth/credentials', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Admin-Password': password }, body: JSON.stringify(payload) });
17621765
const d = await res.json();

0 commit comments

Comments
 (0)