Setting Up Social Login
Social login lets your users sign in with accounts they already have (like Google or GitHub) instead of creating new passwords. This guide shows you how to add Google login to your application - it’s the most popular choice and works great for most applications.
What You’ll Learn
- How to set up Google OAuth for your application
- How to configure Keycloak to use Google as an identity provider
- How to test social login
- Best practices for social authentication
Why Use Social Login?
Benefits for your users:
- No new passwords to remember
- Faster registration and login
- Trust in familiar login screens
- Automatic profile information
Benefits for you:
- Reduced support requests (“I forgot my password”)
- Higher conversion rates
- Less user data to manage and secure
- Built-in email verification
Prerequisites
- A working Keycloak cluster (see First Application Setup)
- A Google account
- Basic understanding of Keycloak realms and clients
Step 1: Create Google OAuth Credentials
Go to Google Cloud Console
- Visit Google Cloud Console
- Sign in with your Google account
-
Create a new project (or select existing one):
- Click the project dropdown (top left)
- Click “New Project”
- Name it “My App Authentication” (or similar)
- Click “Create”
Enable Google+ API
- Go to “APIs & Services” > “Library” (left sidebar)
- Search for “Google+ API”
- Click on it and click “Enable”
Create OAuth 2.0 Credentials
Go to “APIs & Services” > “Credentials”
Click “Create Credentials” > “OAuth 2.0 Client ID”
-
Configure the consent screen (if prompted):
- Choose “External” for most applications
- Fill in required fields:
- App name: “My Application”
- User support email: Your email
- Developer contact: Your email
- Click “Save and Continue”
- Skip scopes for now
- Add test users if needed
- Click “Save and Continue”
-
Create the OAuth client:
- Application type: “Web application”
- Name: “My App Keycloak”
- Authorized redirect URIs: We’ll add this in a moment
- Click “Create”
Get Your Credentials
After creating the client, you’ll see:
-
Client ID: Something like
123456789-abc123.apps.googleusercontent.com -
Client Secret: A random string like
ABC123-def456
Keep these safe! You’ll need them for Keycloak configuration.
Step 2: Configure Keycloak Identity Provider
Add Google Identity Provider
- Open your Keycloak admin console
- Make sure you’re in the correct realm (not “master”)
- Go to “Identity Providers” (left sidebar)
- Click “Google” from the list of providers
Configure Google Settings
Fill in the configuration form:
Basic Settings:
-
Alias:
google(this creates the URL path) -
Display Name:
Google(what users see on the login page) - Client ID: Paste your Google Client ID
- Client Secret: Paste your Google Client Secret
Advanced Settings (recommended):
-
Default Scopes:
openid profile email - Store Tokens: ON (allows users to link/unlink accounts later)
- Trust Email: ON (trusts that Google has verified the email)
Click “Save”
Copy the Redirect URI
After saving, you’ll see a “Redirect URI” field with a URL like:
https://your-cluster.skycloak.io/realms/your-realm/broker/google/endpoint
Copy this URL - you need to add it to Google.
Step 3: Update Google Configuration
Add Redirect URI to Google
- Go back to Google Cloud Console
- Navigate to “APIs & Services” > “Credentials”
- Click on your OAuth 2.0 Client
- Add the Keycloak redirect URI to “Authorized redirect URIs”
- Click “Save”
Step 4: Test Social Login
Create a Test Application
If you haven’t already, create a simple test application (you can use the one from the First Application Setup guide).
Test the Login Flow
Open your application
Click the login button
-
You should now see two options:
- Username/password form
- “Google” button
Click “Google”
You’ll be redirected to Google’s login page
Sign in with your Google account
Grant permissions when prompted
You should be redirected back to your application, now logged in!
What Happens Behind the Scenes
- User clicks “Google” in your app
- Keycloak redirects to Google’s authorization server
- User signs in to Google and grants permissions
- Google redirects back to Keycloak with an authorization code
- Keycloak exchanges the code for tokens from Google
- Keycloak creates a local user account (if first time)
- Keycloak issues its own tokens and redirects to your app
- Your app receives the tokens and logs the user in
Step 5: Customize the Social Login Experience
Customize the Login Page
Add a Logo:
- Go to “Realm Settings” > “Themes”
- Upload a custom logo or use Skycloak’s branding features
- The Google button will appear with your custom styling
Customize Button Text:
- Go to “Identity Providers” > “Google”
- Change “Display Name” to customize the button text
- Examples: “Sign in with Google”, “Continue with Google”
Configure User Information
Map Google Profile to Keycloak:
- Go to “Identity Providers” > “Google” > “Mappers”
-
Add built-in mappers for common fields:
- First Name:
given_name - Last Name:
family_name - Email:
email - Profile Picture:
picture
- First Name:
Create Custom Mappers:
Mapper Type: Attribute Importer
Name: Google Profile Picture
Social Profile JSON Field Path: picture
User Attribute Name: picture_url
Step 6: Handle User Account Linking
Account Linking Strategies
Automatic Linking (Recommended):
- Links accounts with the same email address automatically
- Enabled by default when “Trust Email” is ON
- Works well for most applications
Manual Linking:
- Users can link accounts in their account console
- More control but requires user action
- Good for high-security applications
Configure Account Linking
- Go to “Identity Providers” > “Google”
- Set “Link Only”: OFF (allows new account creation)
- Set “Trust Email”: ON (enables automatic linking)
- Set “First Login Flow”: Review the flow settings
Advanced Configuration
Add Multiple Social Providers
You can add multiple social login options:
GitHub (Great for Developer Tools):
- Create OAuth app at github.com/settings/developers
- Add GitHub identity provider in Keycloak
- Configure redirect URI
Microsoft (Good for Business Apps):
- Register app in Azure AD
- Add Microsoft identity provider
- Configure enterprise features
Facebook (For Consumer Apps):
- Create app at developers.facebook.com
- Add Facebook identity provider
- Configure app review for production
Security Considerations
Email Verification:
- Social providers usually verify emails
- Set “Trust Email” to ON for major providers
- Consider additional verification for sensitive apps
Account Protection:
- Enable account linking protection
- Consider requiring additional authentication for sensitive actions
- Monitor for suspicious login patterns
Data Privacy:
- Review what data you request from social providers
- Only request necessary permissions
- Comply with privacy regulations (GDPR, CCPA)
Troubleshooting
Common Issues
“Invalid Redirect URI” Error:
- Check that the redirect URI in Google matches exactly
- Make sure your Keycloak URL is correct
- Verify HTTPS is used in production
“Client ID Not Found” Error:
- Double-check the Client ID in Keycloak
- Make sure the Google project is enabled
- Verify the Google+ API is enabled
Users Can’t Link Accounts:
- Check “Trust Email” setting
- Verify email addresses match between accounts
- Review first login flow configuration
Social Login Button Doesn’t Appear:
- Make sure the identity provider is enabled
- Check that it’s configured for the correct realm
- Verify your application is using the correct realm
Testing Tips
Use Different Browsers:
- Test with different Google accounts
- Clear cookies between tests
- Try both new user registration and existing user login
Check Logs:
- Review Keycloak server logs for detailed error messages
- Use browser developer tools to see network requests
- Enable debug logging for identity providers
Production Considerations
Google OAuth Verification
For production applications, you may need to verify your OAuth app with Google:
- Complete the OAuth consent screen with all required information
- Add privacy policy and terms of service URLs
- Submit for verification if you request sensitive scopes
- This can take several days, so plan accordingly
Rate Limits and Quotas
- Google has rate limits on OAuth requests
- Monitor your usage in Google Cloud Console
- Consider caching user profile information
- Implement proper error handling for rate limit responses
Monitoring and Analytics
- Track social login adoption rates in the Insights dashboard
- Monitor conversion rates compared to email/password
- Use Skycloak’s analytics to understand user behavior
Best Practices
User Experience
Clear Communication:
- Explain what data you’ll access from their Google account
- Show privacy policy and terms of service
- Provide alternative login methods
Smooth Onboarding:
- Pre-fill forms with social profile data
- Skip email verification if email is trusted
- Guide users through any required additional setup
Technical Implementation
Error Handling:
- Handle cases where users deny permissions
- Provide fallback options for authentication failures
- Show clear error messages for configuration issues
Testing:
- Test with multiple Google accounts
- Verify account linking works correctly
- Test both new user registration and returning user login
Next Steps
Now that you have Google login working:
- Add more providers: Try GitHub, Microsoft, or Facebook
- Customize the experience: Brand your login pages
- Secure your application: Set up multi-factor authentication
- Monitor usage: Use Skycloak’s analytics to track adoption
Related Guides
Remember: Social login is about making things easier for your users while maintaining security. Start with one provider (Google is usually the best choice) and add more based on your users’ needs!