(feat:connector) redirect url as backend overhead

This commit is contained in:
ManishMadan2882
2025-09-03 09:57:13 +05:30
parent 3b3a04a249
commit 7e2cbdd88c
5 changed files with 190 additions and 298 deletions

View File

@@ -1,114 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Google Drive Authentication</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f5f5f5;
}
.container {
text-align: center;
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.success {
color: #4CAF50;
}
.error {
color: #f44336;
}
.loading {
color: #2196F3;
}
</style>
</head>
<body>
<div class="container">
<h2>Google Drive Authentication</h2>
<div id="status" class="loading">Processing authentication...</div>
</div>
<script>
function getUrlParams() {
const urlParams = new URLSearchParams(window.location.search);
return {
code: urlParams.get('code'),
error: urlParams.get('error'),
state: urlParams.get('state')
};
}
async function handleCallback() {
const params = getUrlParams();
const statusDiv = document.getElementById('status');
if (params.error) {
statusDiv.className = 'error';
statusDiv.innerHTML = `Authentication failed: ${params.error}<br><br>
<small>Please try again and make sure to:<br>
1. Grant all requested permissions<br>
2. Allow offline access when prompted<br>
3. Complete the authorization process</small>`;
setTimeout(() => window.close(), 5000);
return;
}
if (!params.code) {
statusDiv.className = 'error';
statusDiv.innerHTML = `No authorization code received.<br><br>
<small>Please try again and make sure to complete the authorization process.</small>`;
setTimeout(() => window.close(), 5000);
return;
}
try {
const backendApiUrl = window.location.protocol + '//' + window.location.hostname + ':7091';
const urlParams = new URLSearchParams(window.location.search);
urlParams.set('provider', 'google_drive');
const response = await fetch(backendApiUrl + '/api/connectors/callback?' + urlParams.toString());
const data = await response.json();
if (data.success) {
// Store session token instead of token_info
if (data.session_token) {
localStorage.setItem('google_drive_session_token', data.session_token);
}
let userEmail = data.user_email || 'Connected User';
statusDiv.className = 'success';
statusDiv.innerHTML = `Authentication successful as ${userEmail}!<br><br>
<small>You can close this window. Your Google Drive is now connected and ready to use.</small>`;
if (window.opener) {
window.opener.postMessage({
type: 'google_drive_auth_success',
session_token: data.session_token,
user_email: userEmail
}, '*');
}
setTimeout(() => window.close(), 3000);
} else {
throw new Error(data.error || 'Authentication failed');
}
} catch (error) {
statusDiv.className = 'error';
statusDiv.innerHTML = `Error: ${error.message}<br><br>
<small>If this is an authentication error, please try again and make sure to grant offline access. You may need to revoke previous access to this app in your Google Account settings and re-authorize.</small>`;
setTimeout(() => window.close(), 5000);
}
}
handleCallback();
</script>
</body>
</html>