From 0cf06b7bd914ad1d99e18d972e1c92248655ce56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Trkan?= Date: Sat, 11 Oct 2025 21:37:49 +0200 Subject: [PATCH] feat(auth): add CustomOpenID class to force get_user_info implementation --- 7project/backend/app/oauth/bank_id.py | 5 +++-- 7project/backend/app/oauth/custom_openid.py | 6 ++++++ 7project/backend/app/oauth/moje_id.py | 5 +++-- 7project/backend/app/services/user_service.py | 6 ++++-- 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 7project/backend/app/oauth/custom_openid.py diff --git a/7project/backend/app/oauth/bank_id.py b/7project/backend/app/oauth/bank_id.py index a522f3a..fa2e55f 100644 --- a/7project/backend/app/oauth/bank_id.py +++ b/7project/backend/app/oauth/bank_id.py @@ -1,11 +1,12 @@ import secrets from typing import Optional, Literal -from httpx_oauth.clients.openid import OpenID from httpx_oauth.oauth2 import T +from app.oauth.custom_openid import CustomOpenID -class BankID(OpenID): + +class BankID(CustomOpenID): def __init__(self, client_id: str, client_secret: str): super().__init__( client_id, diff --git a/7project/backend/app/oauth/custom_openid.py b/7project/backend/app/oauth/custom_openid.py new file mode 100644 index 0000000..226682d --- /dev/null +++ b/7project/backend/app/oauth/custom_openid.py @@ -0,0 +1,6 @@ +from httpx_oauth.clients.openid import OpenID + + +class CustomOpenID(OpenID): + async def get_user_info(self, token: str) -> dict: + raise NotImplementedError() \ No newline at end of file diff --git a/7project/backend/app/oauth/moje_id.py b/7project/backend/app/oauth/moje_id.py index b199f63..7e1cd45 100644 --- a/7project/backend/app/oauth/moje_id.py +++ b/7project/backend/app/oauth/moje_id.py @@ -1,11 +1,12 @@ import json from typing import Optional, Literal, Any -from httpx_oauth.clients.openid import OpenID from httpx_oauth.oauth2 import T +from app.oauth.custom_openid import CustomOpenID -class MojeIDOAuth(OpenID): + +class MojeIDOAuth(CustomOpenID): def __init__(self, client_id: str, client_secret: str): super().__init__( client_id, diff --git a/7project/backend/app/services/user_service.py b/7project/backend/app/services/user_service.py index ab40760..afee558 100644 --- a/7project/backend/app/services/user_service.py +++ b/7project/backend/app/services/user_service.py @@ -10,9 +10,11 @@ from fastapi_users.authentication import ( ) from fastapi_users.authentication.strategy.jwt import JWTStrategy from fastapi_users.db import SQLAlchemyUserDatabase +from httpx_oauth.oauth2 import BaseOAuth2 from app.models.user import User from app.oauth.bank_id import BankID +from app.oauth.custom_openid import CustomOpenID from app.oauth.moje_id import MojeIDOAuth from app.services.db import get_user_db from app.core.queue import enqueue_email @@ -34,7 +36,7 @@ providers = { } -def get_oauth_provider(name: str) -> Optional[MojeIDOAuth]: +def get_oauth_provider(name: str) -> Optional[BaseOAuth2]: if name not in providers: return None return providers[name] @@ -55,7 +57,7 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]): # set additional user info from the OAuth provider provider = get_oauth_provider(oauth_name) - if provider is not None and hasattr(provider, "get_user_info"): + if provider is not None and isinstance(provider, CustomOpenID): update_dict = await provider.get_user_info(access_token) await self.user_db.update(user, update_dict)