Beginner LevelAuthentication & Authorization
How does Social Login (Sign in with Google/GitHub) work via OAuth 2.0 and OIDC?
❓ Interview Prompt: Explain social authentication flows, authorization grants, exchanging code for Google user profiles, and account linking.
Social Login allows users to authenticate to a web application using their existing accounts from major Identity Providers (Google, GitHub, Apple, Facebook).
Execution Flow:
1
User clicks "Sign in with Google".
2
Web app redirects user to Google's OAuth 2.0 authorization URL with requested scopes ('openid email profile').
3
User authenticates at Google and grants permission.
4
Google redirects back to web app callback URI with an authorization code.
5
Web app backend exchanges authorization code for Google ID Token and Access Token.
6
Web app extracts verified user email from ID Token and links/creates local user session.
Code Implementation Example
typescript
// Exchange authorization code for Google user profile
async function getGoogleUserProfile(authCode: string): Promise<{ email: string; name: string }> {
const tokenRes = await fetch('https://oauth2.googleapis.com/token', {
method: 'POST',
body: JSON.stringify({
code: authCode,
client_id: process.env.GOOGLE_CLIENT_ID,
client_secret: process.env.GOOGLE_CLIENT_SECRET,
redirect_uri: 'https://app.company.com/auth/google/callback',
grant_type: 'authorization_code'
})
});
const { id_token } = await tokenRes.json();
const profile = jwt.decode(id_token) as { email: string; name: string };
return profile;
}💡Exchanging Google authorization code for ID Token and decoding user profile claims.
🎯 Interview Key Takeaway
Social login leverages OAuth 2.0/OIDC to delegate authentication to trusted providers like Google or GitHub.
#Social Login#Google Auth#OAuth 2.0#OIDC#Beginner
Back to all Authentication & Authorization Questions→