Custom OAuth Provider
Plug in any OAuth or SSO not in the built-in list.
Need Microsoft, Discord, Slack, Okta, an internal SSO? Extend BaseAuthProvider and pass it to the module.
The contract
The validate method's job: take whatever credentials the client sent, prove they're authentic to the provider, and return a normalized AuthProviderUser with at least a providerId and (when possible) an email.
Registering the provider
The library now accepts POST /auth/login with { providerName: 'discord', credentials: { token } }.
What you get for free
Once validate returns successfully, the library handles:
- Identity lookup (
nest_auth_identitiesrow forprovider='discord'+providerId=<id>). - User creation if the identity is new and
registration.enabled !== false. - Account linking if the email matches an existing user.
- Session creation, JWT minting, and event emission (
UserRegisteredEvent/UserLoggedInEvent).
You only write the part that's specific to the provider — verifying the credential.
When the client sends a code instead of a token
If your provider gives the frontend an authorization code (not an access token), do the code-exchange inside validate:
Wire clientId, clientSecret, etc., as constructor args so they come from your config:
Related
- Google OAuth — implementation-by-example for a built-in.
- Account linking recipe.
- Backend services reference for
AuthProviderRegistryService.