Overview
RealtimeChat uses ASP.NET Core Identity as its authentication framework, providing secure user management with cookie-based authentication and external OAuth provider support.ASP.NET Identity
Built-in user management with secure password hashing and validation
Google OAuth
Social authentication with Google OAuth 2.0 integration
Cookie Authentication
Session-based authentication using secure HTTP-only cookies
Identity API
RESTful endpoints for registration, login, and user management
Authentication System
Core Components
The authentication system is built on several key components:- ApplicationUser Model - Custom user entity extending
IdentityUser - Identity Configuration - Entity Framework Core configuration for identity tables
- External Auth Service - Handles OAuth provider authentication
- Auth Extensions - Configures authentication middleware and endpoints
User Model
TheApplicationUser class extends ASP.NET Identity’s IdentityUser with additional properties:
Applications/RealtimeChat.API/Entities/ApplicationUser.cs
Inherited Properties
FromIdentityUser, the following properties are available:
Unique identifier for the user
Username (typically the email address)
User’s email address
Whether the email has been verified
Hashed password (never stored in plain text)
Optional phone number
Custom Properties
User’s first name (nullable)
User’s last name (nullable)
Navigation property for user’s chat messages
Navigation property for chat room participations
Authentication Flow
Traditional Registration & Login
OAuth Flow (Google)
Authentication Schemes
RealtimeChat configures multiple authentication schemes:Applications/RealtimeChat.API/Extensions/AuthExtensions.cs
- ApplicationScheme - Default scheme for cookie authentication
- ExternalScheme - Used for OAuth provider authentication
API Endpoints
The following authentication endpoints are automatically mapped:Identity API Endpoints
POST /account/register- Register new userPOST /account/login- Login with email/passwordPOST /account/refresh- Refresh authentication tokenGET /account/manage/info- Get current user infoPOST /account/manage/info- Update user info
Custom Endpoints
Security Best Practices
RealtimeChat implements several security best practices:
Password Security
- Passwords are hashed using PBKDF2 with salt
- Plain text passwords are never stored
- ASP.NET Identity handles all password hashing automatically
Cookie Security
- Authentication cookies are HTTP-only (not accessible via JavaScript)
- Cookies are secure in production (HTTPS only)
- Session cookies expire when browser closes (non-persistent by default)
OAuth Security
- OAuth tokens are validated server-side
- External login providers must be explicitly configured
- Callback URLs are restricted to prevent open redirects
Database Security
- Connection strings should be stored in environment variables or Azure Key Vault
- Never commit credentials to source control
- Use separate databases for development and production
Next Steps
OAuth Setup
Configure Google OAuth for social authentication
Identity Configuration
Learn about ASP.NET Identity configuration