OAuth Flow
Last Updated: May 20, 2025
This document provides an overview of the OAuth authentication flow in the Typus Development Framework.
Overview
OAuth (Open Authorization) is an open standard for access delegation, commonly used as a way for users to grant websites or applications access to their information on other websites without giving them passwords. Typus Framework supports OAuth 2.0 integration with popular providers such as Google.
OAuth Flow Diagram
Supported OAuth Providers
The Typus Framework currently supports the following OAuth providers:
- Google
- Authentication via Google accounts
- Access to basic profile information
- Optional access to additional Google services
OAuth Process Steps
1. Initialization
- User clicks "Login with [Provider]" button
- Frontend requests an OAuth initialization from the backend
- Backend generates necessary state parameters and constructs the authorization URL
- User is redirected to the OAuth provider's login page
2. Authorization
- User logs in to the OAuth provider (if not already logged in)
- User authorizes the application to access their information
- OAuth provider redirects back to the application with an authorization code
3. Token Exchange
- Frontend sends the authorization code to the backend
- Backend exchanges the code for an access token with the OAuth provider
- Backend uses the access token to request user information from the provider
4. User Account Management
- Backend checks if the user already exists in the database
- If new user, a new account is created with information from the OAuth provider
- If existing user, the account is updated with the latest information
- User is authenticated and JWT tokens are generated
5. Session Establishment
- Backend returns user data and authentication tokens to the frontend
- Frontend stores tokens for subsequent API requests
- User is redirected to the appropriate page (typically the dashboard)
API Endpoints
The OAuth flow is handled through two main endpoints:
OAuth Initialization Endpoint
- Initiates the OAuth flow with the selected provider
- Redirects the user to the provider's authorization page
OAuth Callback Endpoint
- Handles the callback from the OAuth provider
- Processes the authorization code
- Authenticates the user and returns tokens
Security Considerations
- State Parameter: Used to prevent CSRF attacks by validating that the request and callback are part of the same flow
- Secure Storage: OAuth tokens are securely stored and never exposed to the client
- Scope Limitation: Only requesting the minimum necessary permissions from the OAuth provider
- Token Expiration: Access tokens have limited lifetimes and are refreshed as needed
- HTTPS: All OAuth communication occurs over secure HTTPS connections
Integration with Existing Authentication
The OAuth authentication flow integrates with the existing authentication system:
- Users can link multiple OAuth providers to a single account
- Users can switch between password-based and OAuth-based authentication
- The same JWT tokens are issued regardless of authentication method
- The same session management applies to all authenticated users
Conclusion
The OAuth integration in Typus Framework provides a secure and user-friendly authentication option. By supporting popular OAuth providers, the framework allows users to authenticate without creating new credentials, while maintaining the security and flexibility of the authentication system.