🛡️ Security

OAuth2 & Social Auth Flows

Configure social login and OAuth2 authentication.

Supported Providers

ProviderStrategyStatus
GoogleOAuth2Built-in
GitHubOAuth2Built-in
FacebookOAuth2Built-in
TwitterOAuth1.1aBuilt-in
MicrosoftOAuth2Built-in
LinkedInOAuth2Built-in

OAuth2 Flow

Diagram; its source is available below
Diagram source
sequenceDiagram
    User->>App: Click "Login with Google"
    App->>Google: Redirect to /oauth/authorize
    Google->>User: Login & consent screen
    User->>Google: Approve
    Google->>App: Redirect with auth code
    App->>Google: Exchange code for tokens
    Google-->>App: Access token + profile
    App->>App: Create/link user account
    App-->>User: JWT token

Configuration

# Google
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_CALLBACK_URL=http://localhost:3000/api/auth/google/callback

# GitHub
GITHUB_CLIENT_ID=your-client-id
GITHUB_CLIENT_SECRET=your-client-secret
GITHUB_CALLBACK_URL=http://localhost:3000/api/auth/github/callback

# Facebook
FACEBOOK_CLIENT_ID=your-app-id
FACEBOOK_CLIENT_SECRET=your-app-secret
FACEBOOK_CALLBACK_URL=http://localhost:3000/api/auth/facebook/callback

Implementation

@UseGuards(AuthGuard('google'))
@Get('google')
async googleAuth() {}

@UseGuards(AuthGuard('google'))
@Get('google/callback')
async googleAuthCallback(@Req() req) {
  return this.authService.socialLogin(req.user, 'google');
}

Edit this page

Copyright © 2023-Present Ever Co. LTD.Docs by Sourcey