SSO Integration
Overview
Quick Start
Minimal Integration (10 lines of code)
function login(teamId, projectId) {
// 1. Open SSO popup
const authGuardUrl = 'https://your-auth-guard.run.app';
let ssoUrl = `${authGuardUrl}/v1/auth/sso?origin=${encodeURIComponent(window.location.origin)}`;
// Optional: Login to a specific team
if (teamId) {
ssoUrl += `&team_id=${encodeURIComponent(teamId)}`;
}
// Optional: Login to a specific project (requires team_id)
if (projectId && teamId) {
ssoUrl += `&project_id=${encodeURIComponent(projectId)}`;
}
const popup = window.open(ssoUrl, 'Atlas SSO', 'width=500,height=600,left=100,top=100');
// 2. Listen for auth result
window.addEventListener('message', function handler(event) {
// Verify origin
if (!event.origin.includes('your-auth-guard.run.app')) return;
if (event.data.type === 'ATLAS_AUTH_SUCCESS') {
const { token, user } = event.data;
// 3. Store credentials
localStorage.setItem('auth_token', token);
localStorage.setItem('user', JSON.stringify(user));
// 4. Update your app state
console.log('Logged in as:', user.user_email);
console.log('Team:', user.team_name); // User's team context
console.log('Project:', user.project_name); // User's project context
window.removeEventListener('message', handler);
// Refresh page or update UI
location.reload();
} else if (event.data.type === 'ATLAS_AUTH_ERROR') {
console.error('Login failed:', event.data.error);
window.removeEventListener('message', handler);
}
});
}
// Usage examples:
login(); // Default team/project login
login('ab2785b2-b5d0-4926-92fb-00aae5ec860a'); // Login to specific team
login('ab2785b2-b5d0-4926-92fb-00aae5ec860a', 'cd1234e5-f6g7-8h9i-jklm'); // Login to specific team + projectHTML Button Example
API Reference
GET /v1/auth/sso
GET /v1/auth/ssoParameter
Required
Description
postMessage Events
Success: ATLAS_AUTH_SUCCESS
ATLAS_AUTH_SUCCESSError: ATLAS_AUTH_ERROR
ATLAS_AUTH_ERRORFramework Examples
React
Vue 3
Angular
Making Authenticated API Calls
Fetching User's Teams & Projects
Get User's Teams
Get User's Projects
JavaScript Example
React Hook Example
Team-Specific Login
Security Considerations
Origin Validation
postMessage Security
Token Storage
Troubleshooting
Popup Blocked
CORS Issues
Token Expired
Consumer APIs
Get User's Teams and Projects
Project Metadata API
Permission Requirements
Endpoint
Method
Required Permission
Migration from Callback-Based Flow
Before (Callback-based)
After (Popup-based)
Support
Last updated