Overview
Social login, also known as third-party authentication, allows users to sign in using their existing accounts from popular identity providers. SuperTokens Core doesn’t implement social login directly but provides OAuth 2.0 and SAML capabilities that enable integration with social providers.Supported Methods
SuperTokens Core supports social login through two primary protocols:OAuth 2.0
Use the OAuth 2.0 implementation for modern social providers:- GitHub
- Apple
- Twitter/X
- Microsoft
- Discord
- And any OAuth 2.0 compliant provider
SAML
Use SAML for enterprise identity providers:- Azure AD
- Okta
- OneLogin
- Auth0
- Google Workspace
- ADFS
- And any SAML 2.0 compliant provider
Architecture
Social login in SuperTokens follows a standard flow:Implementation Approaches
1. OAuth 2.0 Based Providers
For providers supporting OAuth 2.0 (Google, Facebook, GitHub, etc.): Step 1: Create OAuth Client2. SAML Based Providers
For enterprise providers supporting SAML (Azure AD, Okta, etc.): Step 1: Create SAML ClientUser Management
Account Linking
Social login accounts can be linked with other authentication methods:- Email/password accounts
- Passwordless accounts
- Other social accounts
- WebAuthn accounts
- Duplicate email detection
- Primary user account management
- Login method aggregation
User Profile Mapping
Map social provider profiles to your user schema: Common Fields:sub/id: Unique provider user IDemail: User’s email addressname: Full namegiven_name: First namefamily_name: Last namepicture: Profile picture URLemail_verified: Email verification status
Provider-Specific Configuration
- Authorization URL:
https://accounts.google.com/o/oauth2/v2/auth - Token URL:
https://oauth2.googleapis.com/token - UserInfo URL:
https://www.googleapis.com/oauth2/v3/userinfo - Scopes:
openid email profile
- Authorization URL:
https://www.facebook.com/v12.0/dialog/oauth - Token URL:
https://graph.facebook.com/v12.0/oauth/access_token - UserInfo URL:
https://graph.facebook.com/me?fields=id,name,email,picture - Scopes:
email public_profile
GitHub
OAuth 2.0 Configuration:- Authorization URL:
https://github.com/login/oauth/authorize - Token URL:
https://github.com/login/oauth/access_token - UserInfo URL:
https://api.github.com/user - Scopes:
user:email
Apple
OAuth 2.0 Configuration:- Authorization URL:
https://appleid.apple.com/auth/authorize - Token URL:
https://appleid.apple.com/auth/token - Scopes:
name email - Special: Requires client secret JWT generation
Azure AD (Microsoft)
SAML or OAuth 2.0:- SAML: Use enterprise application in Azure AD
- OAuth: Use app registration in Azure AD
- Authorization URL:
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize - Token URL:
https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token
Security Considerations
State Parameter
Always use a state parameter to prevent CSRF attacks:PKCE (Proof Key for Code Exchange)
For public clients (mobile/SPA), use PKCE:- Generate code verifier
- Create code challenge (SHA-256 hash)
- Send challenge with authorization request
- Send verifier with token request
Token Validation
Always validate tokens received from providers:- Verify signature (for JWT tokens)
- Check issuer matches expected provider
- Validate audience matches your client ID
- Ensure token hasn’t expired
- Verify nonce (if using OpenID Connect)
Redirect URI Validation
Super Tokens Core validates redirect URIs:- Must match exactly (no wildcards)
- Must use HTTPS in production
- Must be pre-registered with the client
Email Verification
Handling email verification from social providers: Auto-verified emails:- Google: Emails are verified by default
- Facebook: Check
email_verifiedclaim - GitHub: Emails marked as verified in GitHub
- Apple: Emails are verified by default
- Some providers don’t verify emails
- Mark email as unverified in your system
- Trigger email verification flow
Error Handling
Common OAuth Errors
invalid_client: Client authentication failedinvalid_grant: Authorization code is invalid or expiredinvalid_request: Missing or invalid parametersunauthorized_client: Client not authorized for this grant typeunsupported_grant_type: Grant type not supportedaccess_denied: User denied authorization
Common SAML Errors
SAMLResponseVerificationFailed: Signature verification failedInvalidRelayState: Relay state doesn’t matchInvalidClient: SAML client not foundIDPInitiatedLoginDisallowed: IDP-initiated login not allowed
Testing
Test Credentials
Many providers offer test/sandbox environments:- Google: Use OAuth playground
- Facebook: Use test users in app dashboard
- GitHub: Use development OAuth apps
- Azure AD: Use test tenant
Local Testing
For local development:- Use ngrok or similar to expose localhost
- Configure redirect URI to tunnel URL
- Set up test credentials
- Test full authentication flow
Best Practices
- Always use HTTPS: Required by most providers
- Store secrets securely: Use environment variables or secret managers
- Implement state parameter: Prevent CSRF attacks
- Handle errors gracefully: Show user-friendly messages
- Cache user info: Reduce API calls to providers
- Respect rate limits: Implement backoff for provider APIs
- Keep libraries updated: Security patches are important
- Support multiple providers: Give users choice
- Account linking: Allow users to link multiple providers
- Privacy considerations: Only request necessary scopes
Multi-Tenancy
Social login with multi-tenancy:- Each tenant can have different provider configurations
- Users are isolated per tenant
- Provider clients are tenant-specific
- Account linking respects tenant boundaries
Migration
Migrating users from other social login implementations:- Export user data from existing system
- Map provider IDs to SuperTokens format
- Import using bulk import APIs
- Preserve email verification status
- Link accounts as needed