cohex / frontend /public /auth-receiver.html
Hemang Thakur
deploy
d5c104e
<!DOCTYPE html>
<html>
<head>
<title>Completing 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;
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.spinner {
border: 3px solid #f3f3f3;
border-top: 3px solid #3498db;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 20px auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="container">
<h2>Completing authentication...</h2>
<div class="spinner"></div>
<p id="status">Please wait...</p>
</div>
<script>
function updateStatus(message) {
document.getElementById('status').textContent = message;
}
try {
// Extract token from URL
let token = null;
let authData = { type: 'auth-success' };
// For Google and Microsoft (token in hash)
if (window.location.hash) {
const hashParams = new URLSearchParams(window.location.hash.substring(1));
token = hashParams.get('access_token');
}
// For Slack (code in query params)
if (!token && window.location.search) {
const queryParams = new URLSearchParams(window.location.search);
// Check if this is a Slack OAuth response (has code and state=slack)
const code = queryParams.get('code');
const state = queryParams.get('state');
if (code && state === 'slack') {
// This is a Slack OAuth response
token = code; // Use the code as the token for now
authData.code = code;
authData.provider = 'slack';
// Extract team information if available
const team = queryParams.get('team');
const teamId = queryParams.get('team_id');
const teamName = queryParams.get('team_name');
if (team || teamId) {
authData.team_id = teamId || team;
authData.team_name = teamName || team;
}
} else if (code && !token) {
// Legacy Slack handling without state parameter
updateStatus('Slack authentication detected. Using authorization code.');
token = code;
authData.code = code;
authData.provider = 'slack';
}
}
if (token) {
updateStatus('Authentication successful! Closing window...');
// Send token back to parent window
if (window.opener) {
window.opener.postMessage({
...authData,
token: token
}, window.location.origin);
// Close window after a short delay
setTimeout(() => window.close(), 1000);
} else {
updateStatus('Unable to communicate with main window. Please close this window manually.');
}
} else {
updateStatus('Authentication failed');
setTimeout(() => {
if (window.opener) {
window.opener.postMessage({ type: 'auth-failed', error: 'No token received' }, '*');
window.close();
}
}, 3000);
}
} catch (error) {
updateStatus('An error occurred: ' + error.message);
console.error('Auth error:', error);
}
</script>
</body>
</html>