fix: 完善 Codex OAuth 支持 - 回调监听、手动添加提示、端口显示

This commit is contained in:
Yoahoug 2026-01-16 18:09:57 +08:00
parent 01f0d5cb59
commit 7b45c6f876
4 changed files with 39 additions and 2 deletions

View file

@ -40,7 +40,8 @@ import {
loadProviders,
openProviderManager,
showAuthModal,
executeGenerateAuthUrl
executeGenerateAuthUrl,
handleGenerateAuthUrl
} from './provider-manager.js';
import {
@ -226,6 +227,7 @@ window.refreshProviderConfig = refreshProviderConfig;
window.fileUploadHandler = fileUploadHandler;
window.showAuthModal = showAuthModal;
window.executeGenerateAuthUrl = executeGenerateAuthUrl;
window.handleGenerateAuthUrl = handleGenerateAuthUrl;
// 配置管理相关全局函数
window.viewConfig = viewConfig;

View file

@ -1039,6 +1039,34 @@ function showAddProviderForm(providerType) {
return;
}
// Codex OAuth 只支持授权添加,不支持手动添加
if (providerType === 'openai-codex-oauth') {
const form = document.createElement('div');
form.className = 'add-provider-form';
form.innerHTML = `
<h4 data-i18n="modal.provider.addTitle"><i class="fas fa-plus"></i> </h4>
<div class="oauth-only-notice" style="padding: 20px; background: #fef3c7; border: 1px solid #fcd34d; border-radius: 8px; margin: 15px 0;">
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
<i class="fas fa-info-circle" style="color: #d97706; font-size: 24px;"></i>
<strong style="color: #92400e;">Codex 仅支持 OAuth 授权添加</strong>
</div>
<p style="color: #b45309; margin: 0 0 15px 0;">
OpenAI Codex 需要通过 OAuth 授权获取访问令牌无法手动填写凭据请点击下方按钮进行授权
</p>
<button class="btn btn-primary" onclick="window.handleGenerateAuthUrl && window.handleGenerateAuthUrl('openai-codex-oauth'); this.closest('.add-provider-form').remove();">
<i class="fas fa-key"></i> OAuth
</button>
<button class="btn btn-secondary" style="margin-left: 10px;" onclick="this.closest('.add-provider-form').remove()">
<i class="fas fa-times"></i> <span data-i18n="modal.provider.cancel"></span>
</button>
</div>
`;
const providerList = modal.querySelector('.provider-list');
providerList.parentNode.insertBefore(form, providerList);
return;
}
const form = document.createElement('div');
form.className = 'add-provider-form';
form.innerHTML = `

View file

@ -2198,6 +2198,7 @@ export {
openProviderManager,
showAuthModal,
executeGenerateAuthUrl,
handleGenerateAuthUrl,
checkUpdate,
performUpdate
};

View file

@ -254,6 +254,12 @@ function getProviderTypeFields(providerType) {
}
],
'openai-codex-oauth': [
{
id: 'CODEX_OAUTH_CREDS_FILE_PATH',
label: isEn ? 'OAuth Credentials File Path' : 'OAuth凭据文件路径',
type: 'text',
placeholder: isEn ? 'e.g.: configs/codex/oauth_creds.json' : '例如: configs/codex/oauth_creds.json'
},
{
id: 'CODEX_EMAIL',
label: isEn ? 'Email (Optional)' : '邮箱 (选填)',
@ -264,7 +270,7 @@ function getProviderTypeFields(providerType) {
id: 'CODEX_BASE_URL',
label: `Codex Base URL <span class="optional-tag">${t('config.optional')}</span>`,
type: 'text',
placeholder: 'https://chatgpt.com/backend-api/codex'
placeholder: 'https://api.openai.com/v1/codex'
}
]
};