Skip to content

Commit

Permalink
fix: cyclic import
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Dec 30, 2024
1 parent 01e0966 commit 7e052ca
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion supertokens_python/recipe/oauth2provider/api/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from supertokens_python.utils import send_200_response, send_non_200_response
from http.cookies import SimpleCookie

from .utils import get_session

if TYPE_CHECKING:
from ..interfaces import (
APIOptions,
Expand All @@ -40,7 +42,6 @@ async def login(
FrontendRedirectResponse,
ErrorOAuth2Response,
)
from supertokens_python.recipe.session.asyncio import get_session
from supertokens_python.recipe.session.exceptions import TryRefreshTokenError

if api_implementation.disable_login_get is True:
Expand Down
43 changes: 42 additions & 1 deletion supertokens_python/recipe/oauth2provider/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
from urllib.parse import parse_qs, urlparse
import time

from supertokens_python import Supertokens
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
from supertokens_python.recipe.session.interfaces import SessionClaimValidator
from supertokens_python.recipe.session.recipe import SessionRecipe
from supertokens_python.recipe.session.session_request_functions import (
get_session_from_request,
)
from supertokens_python.types import MaybeAwaitable
from ..constants import LOGIN_PATH, AUTH_PATH, END_SESSION_PATH

if TYPE_CHECKING:
Expand Down Expand Up @@ -340,3 +346,38 @@ async def handle_logout_internal_redirects(
redirect_count += 1

return response


async def get_session(
request: Any,
session_required: Optional[bool] = None,
anti_csrf_check: Optional[bool] = None,
check_database: Optional[bool] = None,
override_global_claim_validators: Optional[
Callable[
[List[SessionClaimValidator], SessionContainer, Dict[str, Any]],
MaybeAwaitable[List[SessionClaimValidator]],
]
] = None,
user_context: Union[None, Dict[str, Any]] = None,
) -> Union[SessionContainer, None]:
if user_context is None:
user_context = {}

if session_required is None:
session_required = True

recipe_instance = SessionRecipe.get_instance()
recipe_interface_impl = recipe_instance.recipe_implementation
config = recipe_instance.config

return await get_session_from_request(
request,
config,
recipe_interface_impl,
session_required=session_required,
anti_csrf_check=anti_csrf_check,
check_database=check_database,
override_global_claim_validators=override_global_claim_validators,
user_context=user_context,
)
4 changes: 1 addition & 3 deletions supertokens_python/recipe/oauth2provider/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

from supertokens_python.exceptions import SuperTokensError, raise_general_exception
from supertokens_python.recipe.oauth2provider.api.introspect_token import (
introspect_token_post,
)
from supertokens_python.recipe.oauth2provider.exceptions import OAuth2ProviderError
from supertokens_python.recipe_module import APIHandled, RecipeModule
from supertokens_python.types import User
Expand Down Expand Up @@ -57,6 +54,7 @@
revoke_token_post,
token_post,
user_info_get,
introspect_token_post,
)
from .constants import (
LOGIN_PATH,
Expand Down

0 comments on commit 7e052ca

Please sign in to comment.