Skip to content

A full-stack auth application with a Hummingbird Swift server and iOS mobile client, implementing industry-standard security practices.

License

Notifications You must be signed in to change notification settings

eduardc77/EcommerceApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Swift Authentication Reference Implementation

A comprehensive, production-ready authentication system showcasing modern Swift development practices across backend and iOS platforms.

<<<<<<< HEAD

Preview

Auth Flow

Components

=======

🎯 Project Vision

develop

This project demonstrates best-in-class authentication architecture using the latest Swift technologies and industry security standards. While themed as an ecommerce application for context, the core focus for now is building the most robust, secure, and modern authentication system possible with Swift.

πŸ—οΈ Technical Architecture

πŸ—οΈ Modern Swift Architecture

  • Backend: Built with Hummingbird 2.0 - the next-generation Swift server framework
  • iOS Client: SwiftUI with modern @Observable macro and @MainActor isolation
  • Networking: Actor-based concurrency with automatic token refresh and race condition prevention
  • Security: Keychain storage and JWT token management patterns

πŸ”’ Security Features

  • Multi-Factor Authentication (MFA):
    • TOTP (Time-based One-Time Passwords) with QR code generation
    • Email-based MFA with resend capabilities
    • Recovery codes system with secure backup
    • Granular MFA method selection and management
  • Advanced Session Management:
    • JWT tokens with automatic refresh
    • Actor-isolated token storage preventing race conditions
    • Account lockout with configurable retry policies
    • Rate limiting with permit-based system
  • Social Authentication:
    • Google Sign-In integration
    • Apple Sign In support
    • Unified response handling across all auth methods

πŸ” Authentication & Authorization

  • Core Authentication:
    • Email/Username + Password sign-in
    • Social authentication (Google, Apple)
    • Multi-factor authentication (TOTP, Email)
    • Password reset with email verification
    • Account recovery with backup codes
    • Role-based access control (planned)

πŸ›‘οΈ Security Implementation

  • Password Security:
    • Secure password validation and hashing (bcrypt)
    • Password history tracking
    • Account lockout protection
  • Token Management:
    • JWT-based authentication with refresh tokens
    • Token blacklisting and invalidation
    • Secure token rotation
  • Concurrent session management
  • Protection Mechanisms:
    • Rate limiting with exponential backoff
  • Brute force protection
    • Account lockout with retry policies
    • Certificate pinning (planned)

πŸ“§ Email Communications

  • Verification Flows:
    • Email verification during registration
  • MFA setup notifications
    • Password reset emails
  • Security notifications
  • Integration:
    • SendGrid email service integration
    • Configurable email templates

πŸ“± iOS Client Features

  • Authentication Flow:
    • SwiftUI-based sign up/sign in screens
    • Social authentication integration
    • MFA support with QR code scanning
    • Password recovery flow
  • Secure token storage using Keychain
    • Biometric authentication (planned)
  • User Experience:
    • Real-time form validation
    • Intelligent error handling and recovery
    • Seamless MFA setup with QR codes
    • Progressive authentication flows
    • Localization support (planned)
    • Push notifications (planned)
    • Offline support (planned)

⚑ Technical Features

  • Sophisticated Error Handling: Typed errors with comprehensive HTTP status mapping
  • Network Resilience: Exponential backoff, retry logic, and response caching
  • Security Best Practices: Keychain storage, bearer token injection, secure password reset flows
  • Comprehensive Testing: Full test suite covering auth flows and edge cases

πŸ›οΈ Architecture Overview

Backend (Swift Server)

β”œβ”€β”€ Controllers/
β”‚   β”œβ”€β”€ AuthController.swift         # Core authentication
β”‚   β”œβ”€β”€ EmailMFAController.swift     # Email-based MFA
β”‚   β”œβ”€β”€ TOTPController.swift         # TOTP management
β”‚   β”œβ”€β”€ MFARecoveryController.swift  # Recovery codes
β”‚   β”œβ”€β”€ OAuthController.swift        # OAuth flows
β”‚   β”œβ”€β”€ SocialAuthController.swift   # Social login
β”‚   └── UserController.swift         # User management
β”œβ”€β”€ Models/
β”‚   β”œβ”€β”€ User/                        # User entities and DTOs
β”‚   └── Auth/                        # Authentication models
β”œβ”€β”€ Services/                        # Business logic layer
β”œβ”€β”€ Middleware/                      # Request/response middleware
└── Migrations/                      # Database schema

iOS Client (SwiftUI)

β”œβ”€β”€ Authentication/
β”‚   β”œβ”€β”€ AuthManager.swift            # Central auth orchestration
β”‚   β”œβ”€β”€ TOTPManager.swift            # TOTP MFA management
β”‚   β”œβ”€β”€ EmailVerificationManager.swift # Email verification flows
β”‚   β”œβ”€β”€ SocialAuthManager.swift      # Social login coordination
β”‚   └── Views/                       # SwiftUI authentication views
β”œβ”€β”€ Networking/
β”‚   β”œβ”€β”€ NetworkManager.swift         # Actor-based HTTP client
β”‚   β”œβ”€β”€ AuthorizationManager.swift   # Token lifecycle management
β”‚   β”œβ”€β”€ TokenStore.swift             # Keychain-backed storage
β”‚   └── RetryHandler.swift           # Network resilience
└── Models/                          # Shared data models

πŸ› οΈ Key Technologies

Backend Stack

iOS Stack

  • SwiftUI with @Observable and @MainActor patterns
  • Swift Concurrency - Full async/await with actor isolation
  • Keychain Services - Secure credential storage
  • Network Framework - Modern HTTP client with caching

Security & Infrastructure

πŸš€ Getting Started

Prerequisites

  • Xcode 15.0+ with Swift 5.9+
  • macOS 14.0+ for development
  • PostgreSQL 14+ for backend database
  • Docker (optional) for containerized development

Backend Setup

cd EcommerceServer
swift package resolve
swift run App serve --port 8080

iOS Setup

cd Ecommerce
open Ecommerce.xcodeproj
# Configure your development team and run

Environment Configuration

Copy .env.example to .env and configure:

DATABASE_URL=postgresql://localhost:5432/ecommerce
JWT_SECRET=your-secret-key
SENDGRID_API_KEY=your-sendgrid-key
GOOGLE_CLIENT_ID=your-google-client-id

πŸ“± Features Showcase

Authentication Flows

  • βœ… Email/Username + Password sign-in
  • βœ… Social authentication (Google, Apple)
  • βœ… Multi-factor authentication (TOTP, Email)
  • βœ… Password reset with email verification
  • βœ… Account recovery with backup codes

Security Features

  • βœ… JWT token-based authentication
  • βœ… Automatic token refresh with race condition prevention
  • βœ… Account lockout after failed attempts
  • βœ… Rate limiting and DDoS protection
  • βœ… Secure password hashing (bcrypt)
  • βœ… CSRF protection and secure headers

User Experience

  • βœ… Seamless MFA setup with QR codes
  • βœ… Progressive authentication flows
  • βœ… Intelligent error handling and recovery
  • βœ… Offline-capable with local caching
  • βœ… Accessibility support (VoiceOver, Dynamic Type)

πŸ§ͺ Testing

Backend Tests

cd EcommerceServer
swift test

iOS Tests

# Main app tests (Auth, Managers, etc.)
xcodebuild test -project Ecommerce.xcodeproj -scheme Ecommerce

# Networking layer tests
cd Ecommerce/Networking
swift test

πŸ“š Documentation

πŸ™ Acknowledgments

Built with cutting-edge Swift technologies:

πŸ“„ License

This project is open source and available under the MIT License.


About

A full-stack auth application with a Hummingbird Swift server and iOS mobile client, implementing industry-standard security practices.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages