fix: OIDC Authentication with PKCE for dev bypass
- Fixed operational auth session bug returning False despite valid Mock Session - Removed dev user ID hardcoding logic ensuring auth flow uses the defined config.
This commit is contained in:
1 parent
03b0e33723
commit
8498781c85
2 files changed
+176
-28
No files matched your search
@@ -20,6 +20,11 @@ class AuthService:
|
||||
def is_dev_mode() -> bool:
|
||||
"""Check if application is in development mode."""
|
||||
return current_app.config.get('DEV_MODE', False)
|
||||
|
||||
@staticmethod
|
||||
def is_mock_auth_enabled() -> bool:
|
||||
"""Check if mock authentication mode is enabled."""
|
||||
return current_app.config.get('MOCK_AUTH', False) and current_app.config.get('DEV_MODE', False)
|
||||
|
||||
@staticmethod
|
||||
def ensure_dev_user_exists() -> User:
|
||||
@@ -95,6 +100,82 @@ class AuthService:
|
||||
}
|
||||
|
||||
return dev_user
|
||||
|
||||
@staticmethod
|
||||
def create_mock_user_session() -> dict:
|
||||
"""
|
||||
Create a mock authentication user session with local mock user.
|
||||
|
||||
:return: Dictionary with mock user session data
|
||||
"""
|
||||
config = current_app.config
|
||||
|
||||
# Use configured mock user settings or defaults
|
||||
mock_user = {
|
||||
'id': config.get('MOCK_USER_ID', 'mock_user_001'),
|
||||
'email': config.get('MOCK_USER_EMAIL', 'mock@formeleon.local'),
|
||||
'name': config.get('MOCK_USER_NAME', 'Mock Admin'),
|
||||
'role': config.get('MOCK_USER_ROLE', 'admin'),
|
||||
'sub': f'mock-{uuid.uuid4()}',
|
||||
'tenant_id': config.get('MOCK_TENANT_ID', 'mock_tenant_001'),
|
||||
'dev_mode': True,
|
||||
'mock_auth': True,
|
||||
'authenticated': True
|
||||
}
|
||||
|
||||
return mock_user
|
||||
|
||||
@staticmethod
|
||||
def ensure_mock_user_exists() -> User:
|
||||
"""
|
||||
Ensure the mock user exists in the database.
|
||||
|
||||
:return: User object from database
|
||||
"""
|
||||
config = current_app.config
|
||||
|
||||
user_id = config.get('MOCK_USER_ID', 'mock_user_001')
|
||||
user = User.query.get(user_id)
|
||||
|
||||
if not user:
|
||||
role = UserRole.ADMIN if config.get('MOCK_USER_ROLE', 'admin') == 'admin' else UserRole.USER
|
||||
user = User(
|
||||
id=user_id,
|
||||
email=config.get('MOCK_USER_EMAIL', 'mock@formeleon.local'),
|
||||
name=config.get('MOCK_USER_NAME', 'Mock Admin'),
|
||||
role=role,
|
||||
sub=f'mock-{uuid.uuid4()}'
|
||||
)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
logger.info(f'Created mock user: {user.id}')
|
||||
|
||||
return user
|
||||
|
||||
@staticmethod
|
||||
def ensure_mock_tenant_exists() -> Tenant:
|
||||
"""
|
||||
Ensure the mock tenant exists in the database.
|
||||
|
||||
:return: Tenant object from database
|
||||
"""
|
||||
config = current_app.config
|
||||
|
||||
tenant_id = config.get('MOCK_TENANT_ID', 'mock_tenant_001')
|
||||
tenant = Tenant.query.get(tenant_id)
|
||||
|
||||
if not tenant:
|
||||
tenant = Tenant(
|
||||
id=tenant_id,
|
||||
name='Mock Tenant',
|
||||
public_key=f'mock-key-{uuid.uuid4().hex[:16]}',
|
||||
allowed_origins='*'
|
||||
)
|
||||
db.session.add(tenant)
|
||||
db.session.commit()
|
||||
logger.info(f'Created mock tenant: {tenant.id}')
|
||||
|
||||
return tenant
|
||||
|
||||
@staticmethod
|
||||
def process_oidc_callback(user_info: dict) -> Tuple[Optional[User], Optional[str]]:
|
||||
|
||||
Reference in new issue
Block a user