How OAuth2 Authentication Works
When a user authenticates with an OAuth2 provider through Nhost, the following workflow occurs:The Authentication Flow
-
Initiation: The user starts the authentication process by making a request to
/signin/provider/{provider}(e.g.,/signin/provider/google) - Provider Authentication: Auth redirects the user to the OAuth2 provider’s authentication page where they log in and grant permissions
-
Callback: After successful authentication, the provider redirects back to Auth at
/signin/provider/{provider}/callbackwith an authorization code -
User Management: Auth processes the callback:
- If this is a new user, a user account is automatically created
- The user’s email is flagged as verified (since the OAuth2 provider has already verified it)
- Token Issuance: The user is redirected back to your frontend application with a refresh token
Benefits of OAuth2 Authentication
- Improved User Experience: Users can sign in with accounts they already have
- Enhanced Security: No need to manage passwords; authentication is handled by established providers
- Verified Emails: Email addresses are automatically verified through the OAuth2 provider
- Reduced Registration Friction: Faster onboarding with one-click sign-in