curl --request GET \
--url https://api.example.com/api/auth/google/authorize{
"googleAccessToken": "<string>",
"googleRefreshToken": "<string>",
"googleTokenExpiry": {},
"googleConnectedAt": {},
"googleSearchConsoleConnected": true,
"googleAnalyticsConnected": true
}Initialize Google OAuth flow to connect Search Console and Analytics
curl --request GET \
--url https://api.example.com/api/auth/google/authorize{
"googleAccessToken": "<string>",
"googleRefreshToken": "<string>",
"googleTokenExpiry": {},
"googleConnectedAt": {},
"googleSearchConsoleConnected": true,
"googleAnalyticsConnected": true
}/api/auth/google/authorize?clientId={id}/api/auth/google/callback with authorization codehttps://www.googleapis.com/auth/webmasters.readonly - Read-only access to Search Console datahttps://www.googleapis.com/auth/analytics.readonly - Read-only access to Google Analytics dataopenid - OpenID Connect authenticationemail - User’s email addressprofile - User’s basic profile information/api/auth/google/callback.
true after successful connectiontrue after successful connectionconst connectGoogle = (clientId) => {
// Redirect to OAuth authorization endpoint
window.location.href = `/api/auth/google/authorize?clientId=${clientId}`;
};
// Usage in React component
<button onClick={() => connectGoogle(client.id)}>
Connect Google Account
</button>
// On your dashboard/clients page, check for connection status
import { useSearchParams } from 'next/navigation';
function ClientsPage() {
const searchParams = useSearchParams();
useEffect(() => {
// Check for successful connection
if (searchParams.get('connected') === 'true') {
const clientId = searchParams.get('clientId');
console.log(`Google connected successfully for client ${clientId}`);
// Show success message to user
}
// Check for errors
const error = searchParams.get('error');
if (error) {
switch (error) {
case 'oauth_denied':
console.error('User denied Google access');
break;
case 'oauth_failed':
console.error('OAuth connection failed');
break;
case 'client_not_found':
console.error('Client not found');
break;
}
}
}, [searchParams]);
return <div>Clients Dashboard</div>;
}
/dashboard/clients?connected=true&clientId={id}
Error Cases:
/dashboard/clients?error=oauth_denied/dashboard/clients?error=oauth_failed/dashboard/clients?error=client_not_found/dashboard/clients?error=oauth_failed&details={message}src/lib/utils/refresh-google-token.ts{
"error": "Google token refresh failed",
"code": "TOKEN_REFRESH_FAILED"
}
DELETE /api/clients/{id}/disconnect endpoint. This removes all stored Google credentials for the client.
# This will redirect to Google's OAuth consent screen
curl -L https://your-domain.com/api/auth/google/authorize?clientId=clx1a2b3c4d5e6f7g8h9i0j1k