MCPcopy Index your code
hub / github.com/su-kaka/gcli2api / startAuth

Function startAuth

front/common.js:1047–1086  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1045// OAuth认证相关函数
1046// =====================================================================
1047async function startAuth() {
1048 const projectId = document.getElementById('projectId').value.trim();
1049 AppState.currentProjectId = projectId || null;
1050
1051 const btn = document.getElementById('getAuthBtn');
1052 btn.disabled = true;
1053 btn.textContent = '正在获取认证链接...';
1054
1055 try {
1056 const requestBody = projectId ? { project_id: projectId } : {};
1057 showStatus(projectId ? '使用指定的项目ID生成认证链接...' : '将尝试自动检测项目ID,正在生成认证链接...', 'info');
1058
1059 const response = await fetch('./auth/start', {
1060 method: 'POST',
1061 headers: getAuthHeaders(),
1062 body: JSON.stringify(requestBody)
1063 });
1064
1065 const data = await response.json();
1066
1067 if (response.ok) {
1068 document.getElementById('authUrl').href = data.auth_url;
1069 document.getElementById('authUrl').textContent = data.auth_url;
1070 document.getElementById('authUrlSection').classList.remove('hidden');
1071
1072 const msg = data.auto_project_detection
1073 ? '认证链接已生成(将在认证完成后自动检测项目ID),请点击链接完成授权'
1074 : `认证链接已生成(项目ID: ${data.detected_project_id}),请点击链接完成授权`;
1075 showStatus(msg, 'info');
1076 AppState.authInProgress = true;
1077 } else {
1078 showStatus(`错误: ${data.error || '获取认证链接失败'}`, 'error');
1079 }
1080 } catch (error) {
1081 showStatus(`网络错误: ${error.message}`, 'error');
1082 } finally {
1083 btn.disabled = false;
1084 btn.textContent = '获取认证链接';
1085 }
1086}
1087
1088async function getCredentials() {
1089 if (!AppState.authInProgress) {

Callers

nothing calls this directly

Calls 2

showStatusFunction · 0.85
getAuthHeadersFunction · 0.85

Tested by

no test coverage detected