Automated Action d63fc9b68d Implement complete Enviodeck Authentication API with FastAPI
- Phone number authentication with OTP verification
- Email/password authentication with secure bcrypt hashing
- Third-party OAuth login support for Google and Apple
- JWT token-based authentication system
- Rate limiting for OTP requests (5/minute)
- SQLite database with SQLAlchemy ORM
- Comprehensive user model with multiple auth providers
- Alembic database migrations setup
- API documentation with Swagger/OpenAPI
- Health check and system endpoints
- Environment configuration with security best practices
- Code quality with Ruff linting and formatting

Features:
- POST /auth/request-otp - Request OTP for phone authentication
- POST /auth/verify-otp - Verify OTP and get access token
- POST /auth/signup-email - Email signup with password
- POST /auth/login-email - Email login authentication
- POST /auth/login-google - Google OAuth integration
- POST /auth/login-apple - Apple OAuth integration
- GET /user/me - Get current authenticated user info
- GET / - API information and documentation links
- GET /health - Application health check
2025-06-21 08:59:35 +00:00

61 lines
1.2 KiB
Python

from pydantic import BaseModel, EmailStr, validator
from typing import Optional
class OTPRequest(BaseModel):
phone_number: str
@validator("phone_number")
def validate_phone_number(cls, v):
# Basic phone number validation
if not v.startswith("+"):
raise ValueError("Phone number must start with +")
if len(v) < 10:
raise ValueError("Phone number must be at least 10 characters")
return v
class OTPVerify(BaseModel):
phone_number: str
otp: str
@validator("otp")
def validate_otp(cls, v):
if len(v) != 6 or not v.isdigit():
raise ValueError("OTP must be 6 digits")
return v
class EmailSignup(BaseModel):
email: EmailStr
password: str
name: Optional[str] = None
@validator("password")
def validate_password(cls, v):
if len(v) < 8:
raise ValueError("Password must be at least 8 characters")
return v
class EmailLogin(BaseModel):
email: EmailStr
password: str
class GoogleLogin(BaseModel):
token: str
class AppleLogin(BaseModel):
token: str
class Token(BaseModel):
access_token: str
token_type: str
class TokenData(BaseModel):
user_id: Optional[int] = None