File size: 3,947 Bytes
fa14eea
 
 
 
 
 
 
 
 
7d369c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
title: AdaptiveAuth
emoji: πŸ”
colorFrom: blue
colorTo: indigo
sdk: docker
pinned: false
---

# SAGAR AdaptiveAuth Framework

**SAGAR AdaptiveAuth** is a FREE, open-source authentication framework with JWT, 2FA, and adaptive risk-based authentication.

## Key Features

- πŸ” **JWT Authentication** with token management
- πŸ” **Two-Factor Authentication** (TOTP with QR codes)
- πŸ” **Risk-Based Adaptive Authentication** (Security levels 0-4)
- πŸ” **Behavioral Analysis** (device, IP, location tracking)
- πŸ” **Step-up Authentication** for high-risk scenarios
- πŸ” **Continuous Session Monitoring**
- πŸ” **Anomaly Detection** (brute force, credential stuffing)
- πŸ” **Admin Dashboard** with real-time risk monitoring
- πŸ” **Password Reset** with email verification

## Installation & Quick Start

### 1. Clone the repository
```bash
git clone https://github.com/Sagar1566/HackWack.git
cd HackWack/AdaptiveAuth
```

### 2. Install dependencies
```bash
pip install -r requirements.txt
```

### 3. Run the application
```bash
python main.py
```
The server will start at `http://localhost:8000`

**Alternative:** Use the start script:
- On Windows: Double-click `start_server.bat`
- On Linux/Mac: Run `./start_server.sh`

## How to Use the Framework

### Option 1: Integrate with Your Existing FastAPI App

```python
from fastapi import FastAPI
from adaptiveauth import AdaptiveAuth

app = FastAPI()

# Initialize AdaptiveAuth
auth = AdaptiveAuth(
    database_url="sqlite:///./app.db",
    secret_key="your-super-secret-key"
)

# Mount all authentication routes
app.include_router(auth.router, prefix="/api/v1/auth")
```

### Option 2: Run Standalone Server

Use the main application file to run as a standalone authentication service.

## Available API Endpoints

After starting the server, visit `http://localhost:8000/docs` for interactive API documentation.

### Authentication
- `POST /api/v1/auth/register` - Register new user
- `POST /api/v1/auth/login` - Standard login
- `POST /api/v1/auth/adaptive-login` - Risk-based adaptive login
- `POST /api/v1/auth/step-up` - Step-up verification
- `POST /api/v1/auth/logout` - Logout user

### User Management
- `GET /api/v1/user/profile` - Get user profile
- `PUT /api/v1/user/profile` - Update profile
- `GET /api/v1/user/security` - Security settings
- `GET /api/v1/user/sessions` - Active sessions
- `POST /api/v1/user/change-password` - Change password

### 2FA
- `POST /api/v1/auth/enable-2fa` - Enable 2FA
- `POST /api/v1/auth/verify-2fa` - Verify 2FA
- `POST /api/v1/auth/disable-2fa` - Disable 2FA

### Risk Assessment
- `POST /api/v1/adaptive/assess` - Assess current risk
- `GET /api/v1/adaptive/security-status` - Get security status
- `POST /api/v1/adaptive/verify-session` - Verify session
- `POST /api/v1/adaptive/challenge` - Request challenge
- `POST /api/v1/adaptive/verify` - Verify challenge

### Admin Dashboard
- `GET /api/v1/admin/users` - List users
- `GET /api/v1/admin/statistics` - Dashboard statistics
- `GET /api/v1/admin/risk-events` - Risk events
- `GET /api/v1/risk/overview` - Risk dashboard

## Security Levels

| Level | Risk | Authentication Required | Description |
|-------|------|------------------------|-------------|
| 0 | Low | Password | Known device + IP + browser |
| 1 | Medium | Password | Unknown browser |
| 2 | High | Password + Email | Unknown IP address |
| 3 | High | Password + 2FA | Unknown device |
| 4 | Critical | Blocked | Suspicious activity |

## Examples

Check out `run_example.py` for a complete integration example.

## Testing the Framework

To verify the framework works correctly, run:

```bash
python test_framework.py
```

For detailed testing instructions, see [HOW_TO_TEST.md](HOW_TO_TEST.md).

## License

**MIT License - Completely FREE and OPEN SOURCE**
- βœ… Use in personal projects
- βœ… Use in commercial projects  
- βœ… Modify and distribute
- βœ… No attribution required
- βœ… No licensing fees