Skip to content

Commit ae87956

Browse files
Merge pull request #127 from bg-playground/copilot/rebase-jwt-authentication
Implement JWT authentication backend (Phase 1)
2 parents 50fa285 + 9c485ab commit ae87956

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

backend/app/auth/security.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
from datetime import datetime, timedelta, timezone
22

3+
import bcrypt
34
import jwt
4-
from passlib.context import CryptContext
55

66
from app.config import settings
77

8-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
9-
108

119
def verify_password(plain_password: str, hashed_password: str) -> bool:
12-
return pwd_context.verify(plain_password, hashed_password)
10+
return bcrypt.checkpw(plain_password.encode("utf-8"), hashed_password.encode("utf-8"))
1311

1412

1513
def get_password_hash(password: str) -> str:
16-
return pwd_context.hash(password)
14+
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")
1715

1816

1917
def create_access_token(data: dict) -> str:

backend/app/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from fastapi import FastAPI
24
from fastapi.middleware.cors import CORSMiddleware
35

@@ -39,13 +41,15 @@ async def startup_event():
3941
from app.db.session import AsyncSessionLocal
4042
from app.models.user import User, UserRole
4143

44+
default_password = os.environ.get("DEFAULT_ADMIN_PASSWORD", "admin1234")
45+
4246
async with AsyncSessionLocal() as db:
4347
existing = await get_user_by_email(db, "admin@bgstm.local")
4448
if not existing:
4549
db.add(
4650
User(
4751
email="admin@bgstm.local",
48-
hashed_password=get_password_hash("admin"), # Change on first use!
52+
hashed_password=get_password_hash(default_password),
4953
full_name="Default Admin",
5054
role=UserRole.admin,
5155
)

backend/app/models/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .requirement import PriorityLevel, Requirement, RequirementStatus, RequirementType
66
from .suggestion import LinkSuggestion, SuggestionMethod, SuggestionStatus
77
from .test_case import AutomationStatus, TestCase, TestCaseStatus, TestCaseType
8+
from .user import User, UserRole
89

910
__all__ = [
1011
"Base",
@@ -23,4 +24,6 @@
2324
"LinkSuggestion",
2425
"SuggestionMethod",
2526
"SuggestionStatus",
27+
"User",
28+
"UserRole",
2629
]

backend/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ httpx==0.28.1
1313
aiosqlite==0.22.1
1414
scikit-learn==1.8.0
1515
PyJWT==2.10.1
16-
passlib[bcrypt]==1.7.4
17-
bcrypt==4.2.1
16+
bcrypt>=4.0.0
1817
email-validator==2.2.0
1918

2019
# Optional dependencies for LLM embeddings

0 commit comments

Comments
 (0)