""" Authentication endpoint configurations. """ from typing import TYPE_CHECKING, Dict, Any, Union, Annotated from fastapi import HTTPException, status, Body from ApiValidations.Request.authentication import Login from .auth import ( AuthenticationChangePasswordEventMethods, AuthenticationCheckTokenEventMethods, AuthenticationCreatePasswordEventMethods, AuthenticationDisconnectUserEventMethods, AuthenticationDownloadAvatarEventMethods, AuthenticationForgotPasswordEventMethods, AuthenticationLoginEventMethods, AuthenticationLogoutEventMethods, AuthenticationRefreshEventMethods, AuthenticationRefreshTokenEventMethods, AuthenticationResetPasswordEventMethods, AuthenticationSelectEventMethods, ) from .models import ( ChangePasswordRequestModel, CreatePasswordRequestModel, ForgotRequestModel, LoginData, LoginRequestModel, LogoutRequestModel, SelectionDataEmployee, SelectionDataOccupant, RememberRequestModel, ) from ApiEvents.base_request_model import DictRequestModel from ApiEvents.abstract_class import RouteFactoryConfig, EndpointFactoryConfig, endpoint_wrapper if TYPE_CHECKING: from fastapi import Request from ApiValidations.Custom.token_objects import EmployeeTokenObject, OccupantTokenObject # Type aliases for common types TokenDictType = Union[EmployeeTokenObject, OccupantTokenObject] @endpoint_wrapper("/authentication/select") async def authentication_select_company_or_occupant_type( request: "Request", data: Union[SelectionDataEmployee, SelectionDataOccupant], token_dict: TokenDictType = None ) -> Dict[str, Any]: """ Handle selection of company or occupant type. Args: request: The FastAPI request object data: Selection request data Returns: Dict containing the response data """ return { "headers": dict(request.headers), "data": data, "token": token_dict } @endpoint_wrapper("/authentication/login") async def authentication_login_with_domain_and_creds( request: "Request", data: Login, ) -> Dict[str, Any]: """ Authenticate user with domain and credentials. """ return AuthenticationLoginEventMethods.authentication_login_with_domain_and_creds( request=request, data=data ) @endpoint_wrapper("/authentication/check") async def authentication_check_token_is_valid( request: "Request", data: DictRequestModel, ) -> Dict[str, Any]: """ Check if a token is valid. """ return { "status": "OK", } @endpoint_wrapper("/authentication/refresh") async def authentication_refresh_user_info( request: "Request", data: DictRequestModel, token_dict: TokenDictType = None, ) -> Dict[str, Any]: """ Refresh user information. """ return { "status": "OK", } @endpoint_wrapper("/authentication/change-password") async def authentication_change_password( request: "Request", data: ChangePasswordRequestModel, token_dict: TokenDictType = None, ) -> Dict[str, Any]: """ Change user password. """ return { "status": "OK", } @endpoint_wrapper("/authentication/create-password") async def authentication_create_password( request: "Request", data: CreatePasswordRequestModel, ) -> Dict[str, Any]: """ Create new password. """ return { "status": "OK", } @endpoint_wrapper("/authentication/forgot-password") async def authentication_forgot_password( request: "Request", data: ForgotRequestModel, ) -> Dict[str, Any]: """ Handle forgot password request. """ return { "status": "OK", } @endpoint_wrapper("/authentication/reset-password") async def authentication_reset_password( request: "Request", data: ForgotRequestModel, ) -> Dict[str, Any]: """ Reset password. """ return { "status": "OK", } @endpoint_wrapper("/authentication/disconnect") async def authentication_disconnect_user( request: "Request", data: LogoutRequestModel, token_dict: TokenDictType = None, ) -> Dict[str, Any]: """ Disconnect user. """ return { "status": "OK", } @endpoint_wrapper("/authentication/logout") async def authentication_logout_user( request: "Request", data: LogoutRequestModel, token_dict: TokenDictType = None, ) -> Dict[str, Any]: """ Logout user. """ return { "status": "OK", } @endpoint_wrapper("/authentication/remember") async def authentication_refresher_token( request: "Request", data: RememberRequestModel, token_dict: TokenDictType = None, ) -> Dict[str, Any]: """ Refresh remember token. """ return { "status": "OK", } @endpoint_wrapper("/authentication/avatar") async def authentication_download_avatar( request: "Request", data: DictRequestModel, token_dict: TokenDictType = None, ) -> Dict[str, Any]: """ Download user avatar. """ return { "status": "OK", } prefix = "/authentication" AUTH_CONFIG = RouteFactoryConfig( name="authentication", prefix=prefix, tags=["Authentication"], include_in_schema=True, endpoints=[ EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/select", url_of_endpoint="/authentication/select", endpoint="/select", method="POST", summary="Select company or occupant type", description="Select company or occupant type", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=authentication_select_company_or_occupant_type, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/login", url_of_endpoint="/authentication/login", endpoint="/login", method="POST", summary="Login user with domain and password", description="Login user with domain and password", is_auth_required=False, # Public endpoint is_event_required=False, endpoint_function=authentication_login_with_domain_and_creds, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/check", url_of_endpoint="/authentication/check", endpoint="/check", method="GET", summary="Check access token is valid", description="Check access token is valid", is_auth_required=True, # Needs token validation is_event_required=False, endpoint_function=authentication_check_token_is_valid, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/refresh", url_of_endpoint="/authentication/refresh", endpoint="/refresh", method="GET", summary="Refresh credentials with access token", description="Refresh credentials with access token", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=authentication_refresh_user_info, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/change-password", url_of_endpoint="/authentication/change-password", endpoint="/change-password", method="POST", summary="Change password with access token", description="Change password with access token", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=authentication_change_password, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/create-password", url_of_endpoint="/authentication/create-password", endpoint="/create-password", method="POST", summary="Create password with password token", description="Create password with password token", is_auth_required=False, # Public endpoint is_event_required=False, endpoint_function=authentication_create_password, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/reset-password", url_of_endpoint="/authentication/reset-password", endpoint="/reset-password", method="POST", summary="Reset password with token", description="Reset password with token", is_auth_required=False, # Public endpoint is_event_required=False, endpoint_function=authentication_reset_password, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/disconnect", url_of_endpoint="/authentication/disconnect", endpoint="/disconnect", method="POST", summary="Disconnect user with access token", description="Disconnect user with access token", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=authentication_disconnect_user, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/logout", url_of_endpoint="/authentication/logout", endpoint="/logout", method="POST", summary="Logout user with access token", description="Logout user with access token", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=authentication_logout_user, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/remember", url_of_endpoint="/authentication/remember", endpoint="/remember", method="POST", summary="Refresh token with refresh token", description="Refresh token with refresh token", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=authentication_refresher_token, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/forgot-password", url_of_endpoint="/authentication/forgot-password", endpoint="/forgot-password", method="POST", summary="Request password reset via email", description="Request password reset via email", is_auth_required=False, # Public endpoint is_event_required=False, endpoint_function=authentication_forgot_password, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/avatar", url_of_endpoint="/authentication/avatar", endpoint="/avatar", method="POST", summary="Get user avatar with credentials", description="Get user avatar with credentials", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=authentication_download_avatar, ), ], ).as_dict()