Skip to content

test: setting session cookies #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 0.29
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tests/test-server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import os
import traceback
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar
from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, TypeVar, Union

import override_logging
from accountlinking import add_accountlinking_routes # pylint: disable=import-error
Expand Down Expand Up @@ -55,6 +55,7 @@
from supertokens_python.recipe.session import InputErrorHandlers, SessionContainer
from supertokens_python.recipe.session.framework.flask import verify_session
from supertokens_python.recipe.session.recipe import SessionRecipe
from supertokens_python.recipe.session.utils import TokenTransferMethod
from supertokens_python.recipe.thirdparty.provider import UserFields, UserInfoMap
from supertokens_python.recipe.thirdparty.recipe import ThirdPartyRecipe
from supertokens_python.recipe.totp.recipe import TOTPRecipe
Expand Down Expand Up @@ -298,6 +299,13 @@ async def custom_unauthorised_callback(
)
return response

def get_token_transfer_method(
_: BaseRequest,
__: bool,
___: Dict[str, Any],
) -> Union[TokenTransferMethod, Literal["any"]]:
return recipe_config_json.get("getTokenTransferMethod", "any")

recipe_config_json = json.loads(recipe_config.get("config", "{}"))
recipe_list.append(
session.init(
Expand All @@ -318,6 +326,7 @@ async def custom_unauthorised_callback(
use_dynamic_access_token_signing_key=recipe_config_json.get(
"useDynamicAccessTokenSigningKey"
),
get_token_transfer_method=get_token_transfer_method,
override=session.InputOverrideConfig(
apis=override_builder_with_logging(
"Session.override.apis",
Expand Down
34 changes: 34 additions & 0 deletions tests/test-server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,40 @@ def create_new_session_without_request_response(): # type: ignore

return jsonify(convert_session_to_json(session_container))

@app.route("/test/session/createnewsession", methods=["POST"]) # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this.

def create_new_session(): # type: ignore
data = request.json
if data is None:
return jsonify({"status": "MISSING_DATA_ERROR"})

tenant_id = data.get("tenantId", "public")
from supertokens_python import convert_to_recipe_user_id

fdi_version = request.headers.get("fdi-version")
assert fdi_version is not None
if get_max_version("1.17", fdi_version) == "1.17" or (
get_max_version("2.0", fdi_version) == fdi_version
and get_max_version("3.0", fdi_version) != fdi_version
):
# fdi_version <= "1.17" or (fdi_version >= "2.0" and fdi_version < "3.0")
recipe_user_id = convert_to_recipe_user_id(data["userId"])
else:
recipe_user_id = convert_to_recipe_user_id(data["recipeUserId"])
access_token_payload = data.get("accessTokenPayload", {})
session_data_in_database = data.get("sessionDataInDatabase", {})
user_context = data.get("userContext", {})

session_container = session.create_new_session(
request,
tenant_id,
recipe_user_id,
access_token_payload,
session_data_in_database,
user_context,
)

return jsonify(convert_session_to_json(session_container))

@app.route("/test/session/getallsessionhandlesforuser", methods=["POST"]) # type: ignore
def get_all_session_handles_for_user_api(): # type: ignore
data = request.json
Expand Down
Loading