Overview
MediSync API uses JWT (JSON Web Token) authentication to secure all protected endpoints. This guide covers the complete authentication flow, token management, and authorization requirements.Authentication Flow
1
User Registration
Create a new MediSync account with medical credentials
2
Login Request
Authenticate with email and password to receive a JWT token
3
Token Usage
Include the JWT token in the Authorization header for all API requests
4
Token Refresh
Handle token expiration and refresh as needed
Registration
Create New Account
Register a new healthcare professional account:Registration Requirements
Required Fields
Required Fields
- title: Medical title (Dr., Prof., etc.)
- firstName: First name
- lastName: Last name
- email: Professional email address (must be unique)
- password: Secure password (min 8 characters)
- specialty: Medical specialty
- ehr_system_type: EHR system category
- ehr_system_name: Specific EHR system name
Password Requirements
Password Requirements
- Minimum 8 characters
- Mix of uppercase and lowercase letters
- At least one number
- Special characters recommended
Login
Obtain JWT Token
Authenticate with your registered credentials:Login Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Registered email address |
password | string | Yes | Account password |
remember | boolean | No | Extended session duration |
Using JWT Tokens
Authorization Header
Include your JWT token in theAuthorization header for all protected API calls:
Example API Request
Token Structure
MediSync JWT tokens contain:Authorization Levels
User Identification
Most endpoints require auid (user ID) parameter to identify the requesting user:
Subscription Requirements
Certain endpoints require an active subscription:- Appointment Creation: Creating new appointments
- AI Features: Clinical note generation, diagnosis prediction
- Advanced Analytics: Detailed reporting and insights
Data Access Control
Users can only access their own data:- Doctors: Access only their own patients and appointments
- Patients: Access only their own medical records
- Admin: System-wide access (special permissions)
Error Handling
Authentication Errors
401 Unauthorized
401 Unauthorized
403 Forbidden
403 Forbidden
Common causes:
- Valid token but insufficient permissions
- Subscription required but not active
- Attempting to access another user’s data
Email Not Verified
Email Not Verified
Error:
"Email verification required"Solution: Check email for verification link or resend verificationError Response Format
Token Management
Token Expiration
JWT tokens have a limited lifespan:- Standard tokens: 24 hours
- Remember me tokens: 30 days
- Refresh threshold: Re-authenticate before expiration
Handling Expired Tokens
When you receive a 401 error:- Check if the token has expired
- Re-authenticate to get a new token
- Retry the original request
- Implement automatic refresh in your application
Security Best Practices
Token Storage
- Store tokens securely (encrypted)
- Never expose tokens in URLs
- Use secure, httpOnly cookies when possible
- Clear tokens on logout
Network Security
- Always use HTTPS
- Validate SSL certificates
- Implement request timeouts
- Monitor for unusual access patterns
Rate Limiting
Authentication endpoints have specific rate limits:| Endpoint | Limit | Window |
|---|---|---|
/api/login | 5 attempts | 15 minutes |
/api/register | 3 attempts | 1 hour |
/api/verification/resend | 5 attempts | 30 minutes |