Skip to content
GitHub

Social Authentication

Social authentication allows users to sign in using their existing social media accounts, providing a seamless authentication experience without requiring users to create new accounts.

Social authentication enables users to authenticate using their existing social media accounts, eliminating the need for separate username/password credentials. Guardian supports multiple social authentication providers with a unified API.

  • Faster Onboarding: Users can signin/up with one click

  • Reduced Friction: No need to remember passwords

  • Higher Conversion: Easier sign-up process

  • Trust: Users trust established providers

  • Sign In: Authenticate existing users

  • Sign Up: Register new users

  • Sign In/Up: Automatically sign in if user exists, otherwise sign up (default)

Guardian supports the following social authentication providers:

  • Protocol: OpenID Connect (OIDC)

  • Token Type: ID Token (JWT)

  • Verification: JWKS-based signature verification

  • User Info: Extracted from ID token claims

📖 Complete Google Authentication Guide

  • Protocol: OAuth 2.0

  • Token Type: Access Token

  • Verification: Graph API validation

  • User Info: Retrieved from Graph API

📖 Complete Facebook Authentication Guide

  • Protocol: OpenID Connect

  • Token Type: ID Token or Authorization Code

  • Verification: Provider-specific JWKS

  • User Info: From ID token or UserInfo endpoint

See OIDC Provider Connect section below

Select which provider(s) you want to support:

Each provider requires specific credentials:

Google:

Facebook:

Insert provider credentials into the appropriate database table:

Google:

INSERT INTO google_config (tenant_id, client_id, client_secret) VALUES ('tenant1', 'your_google_client_id', 'your_google_client_secret');

Facebook:

INSERT INTO fb_config (tenant_id, app_id, app_secret, send_app_secret) VALUES ('tenant1', 'your_facebook_app_id', 'your_facebook_app_secret', true);

Follow the provider-specific guide:

For complete implementation details, see the dedicated guides:

Complete guide for Google authentication including:

  • Step-by-step credential setup

  • Database configuration

  • API endpoint details

  • JavaScript and React examples

  • Troubleshooting

Endpoint: POST /v2/auth/google

Complete guide for Facebook authentication including:

  • Step-by-step credential setup

  • Database configuration

  • API endpoint details

  • JavaScript and React examples

  • Troubleshooting

Endpoint: POST /v2/auth/fb

Guardian integrates with your user service to create and retrieve users. Your user service must implement:

  • GET /user - Get user by email, phone, or provider info

  • POST /user - Create new user

  • POST /provider - Add provider to existing user

For custom OIDC providers, use the /v2/idp/connect endpoint.

INSERT INTO oidc_provider_config ( tenant_id, provider_name, issuer, jwks_url, token_url, client_id, client_secret, redirect_uri, client_auth_method, is_ssl_enabled, user_identifier, audience_claims ) VALUES ( 'tenant1', 'custom_provider', 'https://provider.example.com', 'https://provider.example.com/.well-known/jwks.json', 'https://provider.example.com/oauth/token', 'your_client_id', 'your_client_secret', 'https://guardian.example.com/callback', 'client_secret_basic', true, 'email', '["audience1", "audience2"]' );

Endpoint: POST /v2/idp/connect

Request:

{ 
  "id_provider": "custom_provider", 
  "identifier": "authorization_code_or_id_token", 
  "identifier_type": "code", 
  "response_type": "token", 
  "client_id": "aB3dE5fG7hI9jK1lM", 
  "code_verifier": "pkce_code_verifier",
  "nonce": "optional_nonce", 
  "flow": "signinup"
}

Request Parameters:

ParameterTypeRequiredDescription
id_providerstringYesIdentity provider name (configured provider identifier)
identifierstringYesProvider-specific identifier (authorization code or ID token)
identifier_typestringYesType of identifier. Options: “code” (default), “id_token”
response_typestringYesDesired response type. Options: “token”, “code”
client_idstringYesGuardian Client ID
code_verifierstringNoPKCE code verifier (required if code_challenge was used)
noncestringNoNonce value for OIDC flows
flowstringNoAuthentication flow type. Options: “signinup” (default), “signin”, “signup”
meta_infoobjectNoRequest metadata (same structure as passwordless)

Response: 200 OK

{
    "access_token": "eyJhbGci...",
    "refresh_token": "xyz789...",
    "id_token": "eyJhbGci...",
    "sso_token": "eyJhbGci...",
    "token_type": "Bearer",
    "expires_in": 3600,
    "is_new_user": false,
    "idp_credentials": {
        "access_token": "provider_access_token",
        "refresh_token": "provider_refresh_token",
        "id_token": "provider_id_token"
    }
}

Response Parameters:

ParameterTypeDescription
access_tokenstringJWT access token for API authentication
refresh_tokenstringOpaque refresh token for obtaining new access tokens
id_tokenstringOpenID Connect ID token containing user information
sso_tokenstringSingle Sign-On token for cross-application authentication
idp_credentialsjsonA JSON holding the authentication tokens from the external identity provider.
token_typestringToken type. Always “Bearer”
expires_inintegerAccess token expiration time in seconds
is_new_userbooleanIndicates if this is a newly created user
  1. Token Validation: Always validate tokens on the server side

  2. HTTPS: Use HTTPS for all API calls in production

  3. Token Storage: Store tokens securely (httpOnly cookies or secure storage)

  4. Credential Security: Never expose client secrets in client-side code

  5. Nonce: Use nonce for OIDC flows to prevent replay attacks

  6. PKCE: Use PKCE for authorization code flow

  1. Provider Selection: Allow users to choose their preferred provider

  2. Error Handling: Handle provider errors gracefully

  3. Loading States: Show loading states during authentication

  4. Account Linking: Link social accounts to existing accounts when possible

  5. Clear Messages: Provide clear error messages to users

  1. Redirect URIs: Configure correct redirect URIs for each provider

  2. Scopes: Request only necessary scopes

  3. User Identifier: Use consistent user identifier (email recommended)

  4. Provider Updates: Keep provider SDKs updated

  5. Testing: Test with provider’s test/sandbox environments first

Problem: “Invalid credentials”

  • Solution: Verify provider credentials in database match those from provider console

  • Check: Ensure credentials are for the correct tenant

Problem: “Token validation failed”

  • Solution: Check provider API is enabled and accessible

  • Check: Verify token hasn’t expired

Problem: “Redirect URI mismatch”

  • Solution: Add redirect URI to provider’s OAuth settings

  • Check: Ensure redirect URI exactly matches

Problem: “User service error”

  • Solution: Check user service is accessible and returns correct format

  • Check: Verify user service endpoints are implemented correctly