srcpi
04/29/2022, 6:39 AMsrcpi
04/29/2022, 6:39 AMrp_st
04/29/2022, 6:39 AMrp_st
04/29/2022, 6:40 AMrp_st
04/29/2022, 6:40 AMrp_st
04/29/2022, 6:40 AMsrcpi
04/29/2022, 6:46 AMrp_st
04/29/2022, 6:46 AMsrcpi
04/29/2022, 6:47 AMrp_st
04/29/2022, 6:47 AMsrcpi
05/04/2022, 12:41 PMrp_st
05/04/2022, 1:01 PMcookies
that you are returning?srcpi
05/04/2022, 1:06 PMrp_st
05/04/2022, 1:07 PMsrcpi
05/04/2022, 1:39 PMsrcpi
05/04/2022, 1:40 PMsrcpi
05/04/2022, 1:54 PMsrcpi
05/04/2022, 1:55 PMrp_st
05/04/2022, 1:56 PMrp_st
05/04/2022, 1:56 PMsrcpi
05/04/2022, 1:58 PMrp_st
05/04/2022, 1:58 PMsrcpi
05/04/2022, 2:00 PMrp_st
05/04/2022, 2:01 PMrp_st
05/04/2022, 2:01 PMsrcpi
05/04/2022, 2:02 PMsrcpi
05/04/2022, 2:02 PMrp_st
05/04/2022, 2:02 PMsrcpi
05/04/2022, 2:04 PMsrcpi
05/04/2022, 2:04 PMsrcpi
05/04/2022, 2:06 PMrecipe_list=[
session.init(
override=session.InputOverrideConfig(functions=override_functions),
cookie_domain=cookie_domain,
),
from initsrcpi
05/04/2022, 2:06 PMsrcpi
05/04/2022, 2:08 PMrp_st
05/04/2022, 2:09 PMsrcpi
05/04/2022, 2:12 PMrp_st
05/04/2022, 2:12 PMrequest_login = async_rf.get('/login', {???})
-> this is calling the /login API right?
I am very sure we don't such an APIsrcpi
05/04/2022, 2:14 PMrp_st
05/04/2022, 2:14 PMrp_st
05/04/2022, 2:14 PMsrcpi
05/04/2022, 2:23 PMfrom supertokens_python.framework.django.django_middleware import middleware
srcpi
05/04/2022, 2:53 PMsrcpi
05/04/2022, 2:54 PMsrcpi
05/04/2022, 2:54 PMsrcpi
05/04/2022, 2:55 PMfrom supertokens_python.recipe.session.asyncio import (create_new_session)
from supertokens_python.framework.django.django_middleware import middleware
async def create_new_session_view(request: HttpRequest):
await create_new_session(request, 'user_id')
return JsonResponse({'foo': 'bar'})
@pytest.fixture
async def profile_permission(async_rf, client, instances):
workplace, organization, profile = instances
my_middleware = middleware(create_new_session_view)
request_login = async_rf.post('/auth/signinup/code', {'phoneNumber': profile.phone_number})
temp = my_middleware(request_login) # A coroutine
response = await temp
cookies = get_cookies(response)
return cookies
rp_st
05/04/2022, 3:24 PM/auth/signinup/code
. The second step is to consume the code for which you need to call /auth/signinup/code/consume
- which will create a session and call the override you had definedsrcpi
05/04/2022, 3:29 PMpreAuthSessionId status devideId flowtype
, just plain cookie with some headerrp_st
05/04/2022, 3:30 PMsrcpi
05/04/2022, 3:31 PMrp_st
05/04/2022, 3:40 PMrp_st
05/04/2022, 3:40 PMsrcpi
05/04/2022, 3:41 PMsrcpi
05/04/2022, 3:43 PMsrcpi
05/04/2022, 3:43 PMrp_st
05/04/2022, 3:43 PMrp_st
05/04/2022, 3:44 PMsrcpi
05/04/2022, 3:44 PMrp_st
05/04/2022, 3:44 PMrp_st
05/04/2022, 3:45 PMsrcpi
05/05/2022, 4:38 AMasync def create_new_session_view(request: HttpRequest):
await create_new_session(request, 'user_id')
return JsonResponse({'foo': 'bar'})
srcpi
05/05/2022, 4:38 AMrp_st
05/05/2022, 4:43 AMasync def custom_response_view(_: HttpRequest):
pass
And then do:
my_middleware = middleware(custom_response_view)
srcpi
05/05/2022, 4:46 AMsrcpi
05/05/2022, 4:46 AMrp_st
05/05/2022, 4:46 AMresponse
?srcpi
05/05/2022, 4:46 AMrp_st
05/05/2022, 4:47 AMrp_st
05/05/2022, 4:51 AMsrcpi
05/05/2022, 4:53 AMinit
inside tests and start_st()
functions. However, I am using locally running supertokens docker container and think that it should not affect the test. Am I wrong?rp_st
05/05/2022, 4:54 AMkakashi_44
05/05/2022, 5:15 AMasync_rf
an object of RequestFactory
?srcpi
05/05/2022, 5:16 AMkakashi_44
05/05/2022, 5:18 AMAsyncRequestFactory
srcpi
05/05/2022, 5:21 AMsrcpi
05/05/2022, 5:22 AMkakashi_44
05/05/2022, 5:29 AMHello
(success) responsesrcpi
05/05/2022, 5:32 AMsrcpi
05/05/2022, 5:33 AMsrcpi
05/05/2022, 5:33 AMkakashi_44
05/05/2022, 5:33 AMinit
, are you passing mode
as asgi
?rp_st
05/05/2022, 5:45 AMsrcpi
05/05/2022, 5:45 AMrp_st
05/05/2022, 5:46 AMrp_st
05/05/2022, 5:46 AMsrcpi
05/05/2022, 5:47 AMsrcpi
05/05/2022, 5:47 AMrp_st
05/05/2022, 5:48 AMrp_st
05/05/2022, 5:48 AMrp_st
05/05/2022, 5:48 AMrp_st
05/05/2022, 5:48 AMkakashi_44
05/05/2022, 6:15 AMsrcpi
05/05/2022, 6:24 AMsrcpi
05/05/2022, 6:48 AMsrcpi
05/05/2022, 6:53 AMexecreate
05/05/2022, 6:57 AMpython
from typing import Union, Dict, Any
from asgiref.sync import sync_to_async
from django.apps import apps
from supertokens_python.recipe.session.interfaces import RecipeInterface
@sync_to_async
def get_all_profile_roles(user_id):
profile_role_model = apps.get_model('profile', 'ProfileRole')
return list(profile_role_model.objects.filter(profile__supertokens_user_id=user_id))
def override_functions(original_implementation: RecipeInterface):
original_implementation_create_new_session = original_implementation.create_new_session
async def create_new_session(request: Any, user_id: str,
access_token_payload: Union[None, Dict[str, Any]],
session_data: Union[None, Dict[str, Any]], user_context: Dict[str, Any]):
if session_data is None:
session_data = {}
if access_token_payload is None:
access_token_payload = {}
access_token_payload["roles"] = {}
for profile_role in await get_all_profile_roles(user_id):
if profile_role.at not in access_token_payload["roles"]:
access_token_payload["roles"][profile_role.at] = [profile_role.role]
else:
access_token_payload["roles"][profile_role.at].append(profile_role.role)
return await original_implementation_create_new_session(request, user_id, access_token_payload,
session_data, user_context)
original_implementation.create_new_session = create_new_session
return original_implementation
execreate
05/05/2022, 6:57 AMpython
from supertokens_python import init, InputAppInfo, SupertokensConfig
from supertokens_python.recipe import passwordless, session
from supertokens_python.recipe.passwordless import ContactPhoneOnlyConfig
from apps.mysupertokens.otp_delivery import send_text_message
from apps.mysupertokens.overrides import override_functions
def init_supertokens(site_url,
website_domain,
website_base_path,
connection_uri,
api_key):
# ensure cookie domain is '.example.com' if api is hosted on a subdomain
cookie_domain = site_url.removeprefix("http://").removeprefix("https://")
if len(cookie_domain.split(".")) > 2:
cookie_domain = "." + ".".join(cookie_domain.split(".")[-2:])
init(
app_info=InputAppInfo(
app_name="app",
api_domain=site_url,
api_base_path="/auth",
website_domain=website_domain,
website_base_path=website_base_path,
),
supertokens_config=SupertokensConfig(
connection_uri=connection_uri,
api_key=api_key,
),
framework='django',
recipe_list=[
session.init(
override=session.InputOverrideConfig(functions=override_functions),
cookie_domain=cookie_domain,
),
passwordless.init(
flow_type="USER_INPUT_CODE",
contact_config=ContactPhoneOnlyConfig(
create_and_send_custom_text_message=send_text_message
)
)
],
mode='wsgi'
)
execreate
05/05/2022, 7:01 AMrp_st
05/05/2022, 7:02 AMsrcpi
05/05/2022, 7:06 AMpython
from django.http import HttpRequest, HttpResponse, JsonResponse
from supertokens_python.framework.django.django_middleware import middleware
async def create_new_session_view(_: HttpRequest):
pass
@pytest.mark.asyncio
@pytest.fixture
async def profile_permission(async_rf, rf, client, instances):
workplace, organization, profile = instances
my_middleware = middleware(create_new_session_view)
request_login = async_rf.post('/auth/signinup/code', {'phoneNumber': profile.phone_number})
temp = my_middleware(request_login) # A coroutine
response = await temp
cookies = get_cookies(response)
return cookies
srcpi
05/05/2022, 7:06 AMrp_st
05/05/2022, 7:09 AMrp_st
05/05/2022, 7:09 AMrp_st
05/05/2022, 7:10 AMsrcpi
05/05/2022, 7:10 AMrp_st
05/05/2022, 7:10 AMrp_st
05/05/2022, 7:11 AMsrcpi
05/05/2022, 7:16 AMpython
async def create_new_session_view(_: HttpRequest):
pass
@pytest.mark.asyncio
@pytest.fixture
async def profile_permission(async_rf, rf, client, instances):
workplace, organization, profile = instances
init_supertokens(SITE_URL,
SUPERTOKENS_WEBSITE_DOMAIN,
SUPERTOKENS_WEBSITE_BASE_PATH,
SUPERTOKENS_CONNECTION_URI,
SUPERTOKENS_API_KEY)
my_middleware = middleware(create_new_session_view)
request_login = async_rf.post('/auth/signinup/code', {'phoneNumber': profile.phone_number})
temp = my_middleware(request_login) # A coroutine
response = await temp
cookies = get_cookies(response)
return cookies
rp_st
05/05/2022, 7:17 AMsrcpi
05/05/2022, 7:18 AMrp_st
05/05/2022, 7:19 AMrp_st
05/05/2022, 7:20 AMSUPERTOKENS_DEBUG=1
env var when you run pytestsrcpi
05/05/2022, 7:32 AMcom.supertokens {"t": "2022-05-05T07:30:56.181Z", "sdkVer": "0.6.5", "message": "Started SuperTokens with debug logging (supertokens.init called)", "file": "supertokens.py:178"}
com.supertokens {"t": "2022-05-05T07:30:56.181Z", "sdkVer": "0.6.5", "message": "app_info: {
"api_base_path": "/api/auth",
"api_domain": "http://0.0.0.0:8000",
"api_gateway_path": "",
"app_name": "app",
"framework": "django",
"mode": "asgi",
"website_base_path": "/auth",
"website_domain": "http://localhost:3000"
}", "file": "supertokens.py:179"}
com.supertokens {"t": "2022-05-05T07:30:56.181Z", "sdkVer": "0.6.5", "message": "framework: django", "file": "supertokens.py:180"}
com.supertokens {"t": "2022-05-05T07:30:56.182Z", "sdkVer": "0.6.5", "message": "session init: anti_csrf: VIA_TOKEN", "file": "recipe/session/recipe.py:74"}
com.supertokens {"t": "2022-05-05T07:30:56.182Z", "sdkVer": "0.6.5", "message": "session init: cookie_domain: supertokens.io", "file": "recipe/session/recipe.py:76"}
com.supertokens {"t": "2022-05-05T07:30:56.182Z", "sdkVer": "0.6.5", "message": "session init: cookie_same_site: lax", "file": "recipe/session/recipe.py:79"}
com.supertokens {"t": "2022-05-05T07:30:56.182Z", "sdkVer": "0.6.5", "message": "session init: cookie_secure: False", "file": "recipe/session/recipe.py:80"}
com.supertokens {"t": "2022-05-05T07:30:56.182Z", "sdkVer": "0.6.5", "message": "session init: refresh_token_path: /api/auth/session/refresh ", "file": "recipe/session/recipe.py:81"}
com.supertokens {"t": "2022-05-05T07:30:56.182Z", "sdkVer": "0.6.5", "message": "session init: session_expired_status_code: 401", "file": "recipe/session/recipe.py:82"}
srcpi
05/05/2022, 7:32 AMcom.supertokens {"t": "2022-05-05T07:31:04.642Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T07:31:04.642Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: /auth/signinup/code", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-05T07:31:04.812Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T07:31:04.812Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: ", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-05T07:31:04.916Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
srcpi
05/05/2022, 7:32 AMcom.supertokens {"t": "2022-05-05T07:31:04.916Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: /organizations/9a840be7-ebe8-42f5-bd56-13f16ca9fcd1/workplace/6/staff_on_leave", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-05T07:31:04.917Z", "sdkVer": "0.6.5", "message": "getSession: Started", "file": "recipe/session/recipe_implementation.py:134"}
com.supertokens {"t": "2022-05-05T07:31:04.917Z", "sdkVer": "0.6.5", "message": "getSession: rid in header: False", "file": "recipe/session/recipe_implementation.py:138"}
com.supertokens {"t": "2022-05-05T07:31:04.917Z", "sdkVer": "0.6.5", "message": "getSession: request method: GET", "file": "recipe/session/recipe_implementation.py:139"}
com.supertokens {"t": "2022-05-05T07:31:04.917Z", "sdkVer": "0.6.5", "message": "getSession: Value of doAntiCsrfCheck is: False", "file": "recipe/session/recipe_implementation.py:162"}
com.supertokens {"t": "2022-05-05T07:31:04.917Z", "sdkVer": "0.6.5", "message": "errorHandler: Started", "file": "supertokens.py:393"}
com.supertokens {"t": "2022-05-05T07:31:04.917Z", "sdkVer": "0.6.5", "message": "errorHandler: Error is from SuperTokens recipe. Message: invalid jwt", "file": "supertokens.py:394"}
com.supertokens {"t": "2022-05-05T07:31:04.917Z", "sdkVer": "0.6.5", "message": "errorHandler: Checking recipe for match: session", "file": "supertokens.py:403"}
com.supertokens {"t": "2022-05-05T07:31:04.918Z", "sdkVer": "0.6.5", "message": "errorHandler: Matched with recipeID: session", "file": "supertokens.py:406"}
com.supertokens {"t": "2022-05-05T07:31:04.918Z", "sdkVer": "0.6.5", "message": "errorHandler: returning TRY_REFRESH_TOKEN", "file": "recipe/session/recipe.py:152"}
com.supertokens {"t": "2022-05-05T07:31:04.918Z", "sdkVer": "0.6.5", "message": "Sending response to client with status code: 401", "file": "utils.py:111"}
srcpi
05/05/2022, 7:33 AMrp_st
05/05/2022, 7:36 AM/api/auth
, but you are querying /auth/..
. That's why the middleware is not handling the requestsrcpi
05/05/2022, 7:37 AMrp_st
05/05/2022, 7:37 AMsrcpi
05/05/2022, 7:37 AMsrcpi
05/05/2022, 7:37 AMsrcpi
05/05/2022, 7:38 AMcom.supertokens {"t": "2022-05-05T07:36:35.772Z", "sdkVer": "0.6.5", "message": "Started SuperTokens with debug logging (supertokens.init called)", "file": "supertokens.py:178"}
com.supertokens {"t": "2022-05-05T07:36:35.772Z", "sdkVer": "0.6.5", "message": "app_info: {
"api_base_path": "/api/auth",
"api_domain": "http://0.0.0.0:8000",
"api_gateway_path": "",
"app_name": "app",
"framework": "django",
"mode": "asgi",
"website_base_path": "/auth",
"website_domain": "http://localhost:3000"
}", "file": "supertokens.py:179"}
com.supertokens {"t": "2022-05-05T07:36:35.772Z", "sdkVer": "0.6.5", "message": "framework: django", "file": "supertokens.py:180"}
com.supertokens {"t": "2022-05-05T07:36:35.773Z", "sdkVer": "0.6.5", "message": "session init: anti_csrf: VIA_TOKEN", "file": "recipe/session/recipe.py:74"}
com.supertokens {"t": "2022-05-05T07:36:35.773Z", "sdkVer": "0.6.5", "message": "session init: cookie_domain: supertokens.io", "file": "recipe/session/recipe.py:76"}
com.supertokens {"t": "2022-05-05T07:36:35.773Z", "sdkVer": "0.6.5", "message": "session init: cookie_same_site: lax", "file": "recipe/session/recipe.py:79"}
com.supertokens {"t": "2022-05-05T07:36:35.773Z", "sdkVer": "0.6.5", "message": "session init: cookie_secure: False", "file": "recipe/session/recipe.py:80"}
com.supertokens {"t": "2022-05-05T07:36:35.773Z", "sdkVer": "0.6.5", "message": "session init: refresh_token_path: /api/auth/session/refresh ", "file": "recipe/session/recipe.py:81"}
com.supertokens {"t": "2022-05-05T07:36:35.773Z", "sdkVer": "0.6.5", "message": "session init: session_expired_status_code: 401", "file": "recipe/session/recipe.py:82"}
srcpi
05/05/2022, 7:38 AMcom.supertokens {"t": "2022-05-05T07:36:44.190Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T07:36:44.190Z", "sdkVer": "0.6.5", "message": "middleware: requestRID is: None", "file": "supertokens.py:352"}
com.supertokens {"t": "2022-05-05T07:36:44.190Z", "sdkVer": "0.6.5", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:370"}
com.supertokens {"t": "2022-05-05T07:36:44.190Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because no recipe matched", "file": "supertokens.py:379"}
response output in test - None
com.supertokens {"t": "2022-05-05T07:36:44.362Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T07:36:44.362Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: ", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-05T07:36:44.466Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T07:36:44.466Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: /organizations/9dd33b6a-f91d-4800-9686-5c235bff14c9/workplace/15/staff_on_leave", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-05T07:36:44.467Z", "sdkVer": "0.6.5", "message": "getSession: Started", "file": "recipe/session/recipe_implementation.py:134"}
com.supertokens {"t": "2022-05-05T07:36:44.467Z", "sdkVer": "0.6.5", "message": "getSession: rid in header: False", "file": "recipe/session/recipe_implementation.py:138"}
srcpi
05/05/2022, 7:38 AMcom.supertokens {"t": "2022-05-05T07:36:44.467Z", "sdkVer": "0.6.5", "message": "getSession: request method: GET", "file": "recipe/session/recipe_implementation.py:139"}
com.supertokens {"t": "2022-05-05T07:36:44.467Z", "sdkVer": "0.6.5", "message": "getSession: Value of doAntiCsrfCheck is: False", "file": "recipe/session/recipe_implementation.py:162"}
com.supertokens {"t": "2022-05-05T07:36:44.468Z", "sdkVer": "0.6.5", "message": "errorHandler: Started", "file": "supertokens.py:393"}
com.supertokens {"t": "2022-05-05T07:36:44.468Z", "sdkVer": "0.6.5", "message": "errorHandler: Error is from SuperTokens recipe. Message: invalid jwt", "file": "supertokens.py:394"}
com.supertokens {"t": "2022-05-05T07:36:44.468Z", "sdkVer": "0.6.5", "message": "errorHandler: Checking recipe for match: session", "file": "supertokens.py:403"}
com.supertokens {"t": "2022-05-05T07:36:44.468Z", "sdkVer": "0.6.5", "message": "errorHandler: Matched with recipeID: session", "file": "supertokens.py:406"}
com.supertokens {"t": "2022-05-05T07:36:44.469Z", "sdkVer": "0.6.5", "message": "errorHandler: returning TRY_REFRESH_TOKEN", "file": "recipe/session/recipe.py:152"}
com.supertokens {"t": "2022-05-05T07:36:44.469Z", "sdkVer": "0.6.5", "message": "Sending response to client with status code: 401", "file": "utils.py:111"}
rp_st
05/05/2022, 7:41 AMsrcpi
05/05/2022, 7:41 AMsrcpi
05/05/2022, 7:42 AMcom.supertokens {"t": "2022-05-05T07:41:32.992Z", "sdkVer": "0.6.5", "message": "Started SuperTokens with debug logging (supertokens.init called)", "file": "supertokens.py:178"}
com.supertokens {"t": "2022-05-05T07:41:32.992Z", "sdkVer": "0.6.5", "message": "app_info: {
"api_base_path": "/auth",
"api_domain": "http://0.0.0.0:8000",
"api_gateway_path": "",
"app_name": "medhub",
"framework": "django",
"mode": "wsgi",
"website_base_path": "",
"website_domain": "http://localhost:3000"
}", "file": "supertokens.py:179"}
com.supertokens {"t": "2022-05-05T07:41:32.992Z", "sdkVer": "0.6.5", "message": "framework: django", "file": "supertokens.py:180"}
com.supertokens {"t": "2022-05-05T07:41:32.993Z", "sdkVer": "0.6.5", "message": "session init: anti_csrf: NONE", "file": "recipe/session/recipe.py:74"}
com.supertokens {"t": "2022-05-05T07:41:32.993Z", "sdkVer": "0.6.5", "message": "session init: cookie_domain: 0.0", "file": "recipe/session/recipe.py:76"}
com.supertokens {"t": "2022-05-05T07:41:32.993Z", "sdkVer": "0.6.5", "message": "session init: cookie_same_site: lax", "file": "recipe/session/recipe.py:79"}
com.supertokens {"t": "2022-05-05T07:41:32.993Z", "sdkVer": "0.6.5", "message": "session init: cookie_secure: False", "file": "recipe/session/recipe.py:80"}
com.supertokens {"t": "2022-05-05T07:41:32.993Z", "sdkVer": "0.6.5", "message": "session init: refresh_token_path: /auth/session/refresh ", "file": "recipe/session/recipe.py:81"}
com.supertokens {"t": "2022-05-05T07:41:32.993Z", "sdkVer": "0.6.5", "message": "session init: session_expired_status_code: 401", "file": "recipe/session/recipe.py:82"}
srcpi
05/05/2022, 7:42 AMcom.supertokens {"t": "2022-05-05T07:41:42.097Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T07:41:42.098Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: /api/auth/signinup/code", "file": "supertokens.py:347"}
response output in test - None
com.supertokens {"t": "2022-05-05T07:41:42.278Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T07:41:42.278Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: ", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-05T07:41:42.345Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T07:41:42.345Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: /organizations/c411f5b8-6fab-4c1e-a0a0-b55fa3c6b8c7/workplace/21/staff_on_leave", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-05T07:41:42.346Z", "sdkVer": "0.6.5", "message": "getSession: Started", "file": "recipe/session/recipe_implementation.py:134"}
com.supertokens {"t": "2022-05-05T07:41:42.346Z", "sdkVer": "0.6.5", "message": "getSession: rid in header: False", "file": "recipe/session/recipe_implementation.py:138"}
com.supertokens {"t": "2022-05-05T07:41:42.346Z", "sdkVer": "0.6.5", "message": "getSession: request method: GET", "file": "recipe/session/recipe_implementation.py:139"}
com.supertokens {"t": "2022-05-05T07:41:42.346Z", "sdkVer": "0.6.5", "message": "getSession: Value of doAntiCsrfCheck is: False", "file": "recipe/session/recipe_implementation.py:162"}
srcpi
05/05/2022, 7:42 AMcom.supertokens {"t": "2022-05-05T07:41:42.346Z", "sdkVer": "0.6.5", "message": "errorHandler: Started", "file": "supertokens.py:393"}
com.supertokens {"t": "2022-05-05T07:41:42.347Z", "sdkVer": "0.6.5", "message": "errorHandler: Error is from SuperTokens recipe. Message: invalid jwt", "file": "supertokens.py:394"}
com.supertokens {"t": "2022-05-05T07:41:42.347Z", "sdkVer": "0.6.5", "message": "errorHandler: Checking recipe for match: session", "file": "supertokens.py:403"}
com.supertokens {"t": "2022-05-05T07:41:42.347Z", "sdkVer": "0.6.5", "message": "errorHandler: Matched with recipeID: session", "file": "supertokens.py:406"}
com.supertokens {"t": "2022-05-05T07:41:42.347Z", "sdkVer": "0.6.5", "message": "errorHandler: returning TRY_REFRESH_TOKEN", "file": "recipe/session/recipe.py:152"}
com.supertokens {"t": "2022-05-05T07:41:42.347Z", "sdkVer": "0.6.5", "message": "Sending response to client with status code: 401", "file": "utils.py:111"}
srcpi
05/05/2022, 7:46 AM/auth
rp_st
05/05/2022, 7:47 AMsrcpi
05/05/2022, 7:48 AMNone
to bad requestsrcpi
05/05/2022, 7:48 AM<HttpResponse status_code=400, "application/json; charset=utf-8"> {'headers': {'Content-Type': 'application/json; charset=utf-8'}, '_charset': None, '_resource_closers': [], '_handler_class': None, 'cookies': <SimpleCookie: >, 'closed': False, '_reason_phrase': None, '_container': [b'{"message":"Please provide exactly one of email or phoneNumber"}'], 'status_code': 400}
rp_st
05/05/2022, 7:50 AMsrcpi
05/05/2022, 7:50 AMrp_st
05/05/2022, 7:51 AMsrcpi
05/05/2022, 7:51 AMrp_st
05/05/2022, 7:52 AMsrcpi
05/05/2022, 9:33 AMsrcpi
05/05/2022, 9:33 AMsrcpi
05/05/2022, 9:33 AMrp_st
05/05/2022, 9:34 AMsend_text_message
functionsrcpi
05/05/2022, 9:35 AMrp_st
05/05/2022, 9:35 AMsend_text_message
into an empty function.srcpi
05/05/2022, 10:04 AMsrcpi
05/05/2022, 11:16 AMPOST /auth/signiniup/code
i should POST /auth/signinup/code/consume
to trigger override functions
from here https://discord.com/channels/603466164219281420/969488117474132038/971666992224415784 and get a user role in cookiessrcpi
05/05/2022, 11:25 AMPOST /auth/signinup/code
i receive this output
{'headers': {'Content-Type': 'application/json; charset=utf-8'}, '_charset': None, '_resource_closers': [], '_handler_class': None, 'cookies': , 'closed': False, '_reason_phrase': None, '_container': [b'{"status":"OK","deviceId":"eQtggkr2pDmaPeCNBKOlGD+lMUitynJ7NLh4Knm0Cu8=","preAuthSessionId":"HhC4t0sQNUrWeOXGk0SIjFUtG4qXv-WIwvHL5H07JN4=","flowType":"USER_INPUT_CODE"}'], 'status_code': 200}
note that cookies are empty at this pointrp_st
05/05/2022, 11:55 AMrp_st
05/05/2022, 11:55 AMsrcpi
05/05/2022, 11:57 AMsrcpi
05/05/2022, 11:57 AMlinkCode
required in consume API?srcpi
05/05/2022, 11:59 AMrp_st
05/05/2022, 12:01 PMsend_text_message
function.srcpi
05/05/2022, 2:00 PMpython
request_login = async_rf.post('/auth/signinup/code/consume',
{'preAuthSessionId': pre_auth_session_id,
'linkCode': "735o/fUDXS/+zwSL5qsT9klwKxRCtoNsUdnNc7GExDM=+772686"},
content_type='application/json')
srcpi
05/05/2022, 2:01 PM772686
is OTP sent to send_text_messagesrcpi
05/05/2022, 2:04 PMcom.supertokens {"t": "2022-05-05T14:02:49.649Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-05T14:02:49.650Z", "sdkVer": "0.6.5", "message": "middleware: requestRID is: None", "file": "supertokens.py:352"}
com.supertokens {"t": "2022-05-05T14:02:49.650Z", "sdkVer": "0.6.5", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:370"}
com.supertokens {"t": "2022-05-05T14:02:49.650Z", "sdkVer": "0.6.5", "message": "middleware: Checking recipe ID for match: passwordless", "file": "supertokens.py:370"}
com.supertokens {"t": "2022-05-05T14:02:49.650Z", "sdkVer": "0.6.5", "message": "middleware: Matched with recipe ID: passwordless", "file": "supertokens.py:377"}
com.supertokens {"t": "2022-05-05T14:02:49.650Z", "sdkVer": "0.6.5", "message": "middleware: Request being handled by recipe. ID is: /signinup/code/consume", "file": "supertokens.py:383"}
com.supertokens {"t": "2022-05-05T14:02:49.662Z", "sdkVer": "0.6.5", "message": "errorHandler: Started", "file": "supertokens.py:393"}
com.supertokens {"t": "2022-05-05T14:02:49.663Z", "sdkVer": "0.6.5", "message": "errorHandler: Error is from SuperTokens recipe. Message: SuperTokens core threw an error for a POST request to path: /recipe/signinup/code/consume with status code: 400 and message: Input encoding error in linkCode
", "file": "supertokens.py:394"}
rp_st
05/05/2022, 2:10 PMsrcpi
05/05/2022, 2:11 PMrp_st
05/05/2022, 2:11 PMrp_st
05/05/2022, 2:12 PMrp_st
05/05/2022, 2:12 PMsrcpi
05/05/2022, 2:13 PMrp_st
05/05/2022, 2:14 PMsrcpi
05/05/2022, 2:21 PMrp_st
05/05/2022, 2:21 PMsrcpi
05/05/2022, 2:22 PMsrcpi
05/06/2022, 7:22 AMpython
async def create_new_session_view(_: HttpRequest):
pass
async def profile_permission(admin_client, async_rf, rf, client, instances):
# Unrelated code here
# Finish sign in/up process with passwordless
my_middleware = middleware(create_new_session_view)
request_login = async_rf.post('/auth/signinup/code/consume',
{'preAuthSessionId': pre_auth_session_id,
'deviceId': device_id,
'userInputCode': otp},
content_type='application/json')
temp = my_middleware(request_login) # A coroutine
response = await temp
cookies = get_cookies(response) # get_cookies() is from Supertokens tests
return cookies
def test_permission(profile_permission, admin_client, instances):
workplace, organization, profile = instances
admin_client.session.cookies = profile_permission
response = admin_client.get(reverse('staff-on-leave-list', kwargs={'organization_pk': organization.id, 'workplace_pk': workplace.id}))
print(response.status_code)
srcpi
05/06/2022, 7:23 AMprofile_permission
is initialized automatically as it is a pytest fixture.srcpi
05/06/2022, 7:24 AMPOST /auth/signinup/code/consume
request with get_cookies function I got from Supertoken testssrcpi
05/06/2022, 7:24 AMdjango.test.Client
which is admin_client
in our casesrcpi
05/06/2022, 7:25 AMcom.supertokens {"t": "2022-05-06T07:13:35.652Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-06T07:13:35.652Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: /organizations/926c4daf-0242-4148-96b3-9c749ca51048/workplace/9/staff_on_leave", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-06T07:13:35.653Z", "sdkVer": "0.6.5", "message": "getSession: Started", "file": "recipe/session/recipe_implementation.py:134"}
com.supertokens {"t": "2022-05-06T07:13:35.653Z", "sdkVer": "0.6.5", "message": "getSession: rid in header: False", "file": "recipe/session/recipe_implementation.py:138"}
com.supertokens {"t": "2022-05-06T07:13:35.653Z", "sdkVer": "0.6.5", "message": "getSession: request method: GET", "file": "recipe/session/recipe_implementation.py:139"}
com.supertokens {"t": "2022-05-06T07:13:35.654Z", "sdkVer": "0.6.5", "message": "getSession: Value of doAntiCsrfCheck is: False", "file": "recipe/session/recipe_implementation.py:162"}
com.supertokens {"t": "2022-05-06T07:13:35.654Z", "sdkVer": "0.6.5", "message": "errorHandler: Started", "file": "supertokens.py:393"}
srcpi
05/06/2022, 7:25 AMcom.supertokens {"t": "2022-05-06T07:13:35.654Z", "sdkVer": "0.6.5", "message": "errorHandler: Error is from SuperTokens recipe. Message: invalid jwt", "file": "supertokens.py:394"}
com.supertokens {"t": "2022-05-06T07:13:35.654Z", "sdkVer": "0.6.5", "message": "errorHandler: Checking recipe for match: session", "file": "supertokens.py:403"}
com.supertokens {"t": "2022-05-06T07:13:35.654Z", "sdkVer": "0.6.5", "message": "errorHandler: Matched with recipeID: session", "file": "supertokens.py:406"}
com.supertokens {"t": "2022-05-06T07:13:35.654Z", "sdkVer": "0.6.5", "message": "errorHandler: returning TRY_REFRESH_TOKEN", "file": "recipe/session/recipe.py:152"}
com.supertokens {"t": "2022-05-06T07:13:35.655Z", "sdkVer": "0.6.5", "message": "Sending response to client with status code: 401", "file": "utils.py:111"}
srcpi
05/06/2022, 7:25 AMrp_st
05/06/2022, 7:33 AMadmin_client.session.cookies
?srcpi
05/06/2022, 7:37 AMAttributeError: 'SessionStore' object has no attribute 'cookies'
srcpi
05/06/2022, 7:39 AMAttributeError: 'dict' object has no attribute 'key'
rp_st
05/06/2022, 7:40 AMpip install git+https://github.com/supertokens/supertokens-python.git@8133d969683d243eb9aeb65102bc45b8a2045df4
in your project and run the test with that?rp_st
05/06/2022, 7:40 AMsrcpi
05/06/2022, 7:41 AMrp_st
05/06/2022, 7:41 AMsrcpi
05/06/2022, 7:43 AMsrcpi
05/06/2022, 7:44 AMrp_st
05/06/2022, 7:46 AMrp_st
05/06/2022, 7:46 AMsrcpi
05/06/2022, 7:47 AMDEBUG com.supertokens:supertokens.py:339 {"t": "2022-05-06T07:46:44.379Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
DEBUG com.supertokens:supertokens.py:347 {"t": "2022-05-06T07:46:44.380Z", "sdkVer": "0.6.5", "message": "middleware: Not handling because request path did not start with config path. Request path: ", "file": "supertokens.py:347"}
DEBUG com.supertokens:supertokens.py:339 {"t": "2022-05-06T07:46:44.424Z", "sdkVer": "0.6.5", "message": "middleware: Started", "file": "supertokens.py:339"}
DEBUG com.supertokens:supertokens.py:352 {"t": "2022-05-06T07:46:44.424Z", "sdkVer": "0.6.5", "message": "middleware: requestRID is: None", "file": "supertokens.py:352"}
DEBUG com.supertokens:supertokens.py:370 {"t": "2022-05-06T07:46:44.424Z", "sdkVer": "0.6.5", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:370"}
DEBUG com.supertokens:supertokens.py:370 {"t": "2022-05-06T07:46:44.424Z", "sdkVer": "0.6.5", "message": "middleware: Checking recipe ID for match: passwordless", "file": "supertokens.py:370"}
DEBUG com.supertokens:supertokens.py:377 {"t": "2022-05-06T07:46:44.425Z", "sdkVer": "0.6.5", "message": "middleware: Matched with recipe ID: passwordless", "file": "supertokens.py:377"}
DEBUG com.supertokens:supertokens.py:383 {"t": "2022-05-06T07:46:44.425Z", "sdkVer": "0.6.5", "message": "middleware: Request being handled by recipe. ID is: /signinup/code", "file": "supertokens.py:383"}
DEBUG com.supertokens:utils.py:121 {"t": "2022-05-06T07:46:44.460Z", "sdkVer": "0.6.5", "message": "Sending response to client with status code: 200", "file": "utils.py:121"}
rp_st
05/06/2022, 7:47 AMrp_st
05/06/2022, 7:47 AMrp_st
05/06/2022, 7:48 AMsrcpi
05/06/2022, 7:48 AMsrcpi
05/06/2022, 7:54 AMDEBUG com.supertokens:supertokens.py:339 {"t": "2022-05-06T07:53:34.670Z", "sdkVer": "0.7.0", "message": "middleware: Started", "file": "supertokens.py:339"}
DEBUG com.supertokens:supertokens.py:347 {"t": "2022-05-06T07:53:34.671Z", "sdkVer": "0.7.0", "message": "middleware: Not handling because request path did not start with config path. Request path: ", "file": "supertokens.py:347"}
DEBUG com.supertokens:supertokens.py:339 {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Started", "file": "supertokens.py:339"}
DEBUG com.supertokens:supertokens.py:352 {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: requestRID is: None", "file": "supertokens.py:352"}
DEBUG com.supertokens:supertokens.py:370 {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:370"}
DEBUG com.supertokens:supertokens.py:370 {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Checking recipe ID for match: passwordless", "file": "supertokens.py:370"}
DEBUG com.supertokens:supertokens.py:377 {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Matched with recipe ID: passwordless", "file": "supertokens.py:377"}
DEBUG com.supertokens:supertokens.py:383 {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Request being handled by recipe. ID is: /signinup/code", "file": "supertokens.py:383"}
DEBUG com.supertokens:utils.py:126 {"t": "2022-05-06T07:53:34.743Z", "sdkVer": "0.7.0", "message": "Sending response to client with status code: 200", "file": "utils.py:126"}
DEBUG com.supertokens:supertokens.py:388 {"t": "2022-05-06T07:53:34.743Z", "sdkVer": "0.7.0", "message": "middleware: Ended", "file": "supertokens.py:388"}
srcpi
05/06/2022, 7:54 AMDEBUG com.supertokens:supertokens.py:339 {"t": "2022-05-06T07:53:34.743Z", "sdkVer": "0.7.0", "message": "middleware: Started", "file": "supertokens.py:339"}
DEBUG com.supertokens:supertokens.py:352 {"t": "2022-05-06T07:53:34.743Z", "sdkVer": "0.7.0", "message": "middleware: requestRID is: None", "file": "supertokens.py:352"}
DEBUG com.supertokens:supertokens.py:370 {"t": "2022-05-06T07:53:34.744Z", "sdkVer": "0.7.0", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:370"}
DEBUG com.supertokens:supertokens.py:370 {"t": "2022-05-06T07:53:34.744Z", "sdkVer": "0.7.0", "message": "middleware: Checking recipe ID for match: passwordless", "file": "supertokens.py:370"}
DEBUG com.supertokens:supertokens.py:377 {"t": "2022-05-06T07:53:34.744Z", "sdkVer": "0.7.0", "message": "middleware: Matched with recipe ID: passwordless", "file": "supertokens.py:377"}
DEBUG com.supertokens:supertokens.py:383 {"t": "2022-05-06T07:53:34.744Z", "sdkVer": "0.7.0", "message": "middleware: Request being handled by recipe. ID is: /signinup/code/consume", "file": "supertokens.py:383"}
DEBUG com.supertokens:utils.py:126 {"t": "2022-05-06T07:53:34.794Z", "sdkVer": "0.7.0", "message": "Sending response to client with status code: 200", "file": "utils.py:126"}
DEBUG com.supertokens:supertokens.py:388 {"t": "2022-05-06T07:53:34.794Z", "sdkVer": "0.7.0", "message": "middleware: Ended", "file": "supertokens.py:388"}
rp_st
05/06/2022, 7:55 AMsrcpi
05/06/2022, 7:55 AMsrcpi
05/06/2022, 7:55 AMsrcpi
05/06/2022, 7:56 AMcom.supertokens {"t": "2022-05-06T07:53:24.602Z", "sdkVer": "0.7.0", "message": "Started SuperTokens with debug logging (supertokens.init called)", "file": "supertokens.py:178"}
com.supertokens {"t": "2022-05-06T07:53:24.602Z", "sdkVer": "0.7.0", "message": "app_info: {
"api_base_path": "/auth",
"api_domain": "http://0.0.0.0:8000",
"api_gateway_path": "",
"app_name": "medhub",
"framework": "django",
"mode": "wsgi",
"website_base_path": "",
"website_domain": "http://localhost:3000"
}", "file": "supertokens.py:179"}
com.supertokens {"t": "2022-05-06T07:53:24.602Z", "sdkVer": "0.7.0", "message": "framework: django", "file": "supertokens.py:180"}
com.supertokens {"t": "2022-05-06T07:53:24.602Z", "sdkVer": "0.7.0", "message": "session init: anti_csrf: NONE", "file": "recipe/session/recipe.py:74"}
com.supertokens {"t": "2022-05-06T07:53:24.603Z", "sdkVer": "0.7.0", "message": "session init: cookie_domain: 0.0", "file": "recipe/session/recipe.py:76"}
com.supertokens {"t": "2022-05-06T07:53:24.603Z", "sdkVer": "0.7.0", "message": "session init: cookie_same_site: lax", "file": "recipe/session/recipe.py:79"}
com.supertokens {"t": "2022-05-06T07:53:24.603Z", "sdkVer": "0.7.0", "message": "session init: cookie_secure: False", "file": "recipe/session/recipe.py:80"}
com.supertokens {"t": "2022-05-06T07:53:24.603Z", "sdkVer": "0.7.0", "message": "session init: refresh_token_path: /auth/session/refresh ", "file": "recipe/session/recipe.py:81"}
com.supertokens {"t": "2022-05-06T07:53:24.603Z", "sdkVer": "0.7.0", "message": "session init: session_expired_status_code: 401", "file": "recipe/session/recipe.py:82"}
srcpi
05/06/2022, 7:56 AMcom.supertokens {"t": "2022-05-06T07:53:34.670Z", "sdkVer": "0.7.0", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-06T07:53:34.671Z", "sdkVer": "0.7.0", "message": "middleware: Not handling because request path did not start with config path. Request path: ", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: requestRID is: None", "file": "supertokens.py:352"}
com.supertokens {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:370"}
com.supertokens {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Checking recipe ID for match: passwordless", "file": "supertokens.py:370"}
com.supertokens {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Matched with recipe ID: passwordless", "file": "supertokens.py:377"}
com.supertokens {"t": "2022-05-06T07:53:34.708Z", "sdkVer": "0.7.0", "message": "middleware: Request being handled by recipe. ID is: /signinup/code", "file": "supertokens.py:383"}
com.supertokens {"t": "2022-05-06T07:53:34.743Z", "sdkVer": "0.7.0", "message": "Sending response to client with status code: 200", "file": "utils.py:126"}
com.supertokens {"t": "2022-05-06T07:53:34.743Z", "sdkVer": "0.7.0", "message": "middleware: Ended", "file": "supertokens.py:388"}
com.supertokens {"t": "2022-05-06T07:53:34.743Z", "sdkVer": "0.7.0", "message": "middleware: Started", "file": "supertokens.py:339"}
srcpi
05/06/2022, 7:57 AMcom.supertokens {"t": "2022-05-06T07:53:34.743Z", "sdkVer": "0.7.0", "message": "middleware: requestRID is: None", "file": "supertokens.py:352"}
com.supertokens {"t": "2022-05-06T07:53:34.744Z", "sdkVer": "0.7.0", "message": "middleware: Checking recipe ID for match: session", "file": "supertokens.py:370"}
com.supertokens {"t": "2022-05-06T07:53:34.744Z", "sdkVer": "0.7.0", "message": "middleware: Checking recipe ID for match: passwordless", "file": "supertokens.py:370"}
com.supertokens {"t": "2022-05-06T07:53:34.744Z", "sdkVer": "0.7.0", "message": "middleware: Matched with recipe ID: passwordless", "file": "supertokens.py:377"}
com.supertokens {"t": "2022-05-06T07:53:34.744Z", "sdkVer": "0.7.0", "message": "middleware: Request being handled by recipe. ID is: /signinup/code/consume", "file": "supertokens.py:383"}
com.supertokens {"t": "2022-05-06T07:53:34.794Z", "sdkVer": "0.7.0", "message": "Sending response to client with status code: 200", "file": "utils.py:126"}
com.supertokens {"t": "2022-05-06T07:53:34.794Z", "sdkVer": "0.7.0", "message": "middleware: Ended", "file": "supertokens.py:388"}
rp_st
05/06/2022, 7:57 AMsrcpi
05/06/2022, 7:59 AMcom.supertokens {"t": "2022-05-06T07:58:52.550Z", "sdkVer": "0.7.0", "message": "middleware: Started", "file": "supertokens.py:339"}
com.supertokens {"t": "2022-05-06T07:58:52.550Z", "sdkVer": "0.7.0", "message": "middleware: Not handling because request path did not start with config path. Request path: /organizations/46ee7e8b-7c31-4101-8c32-dddbc87ee179/workplace/9/staff_on_leave", "file": "supertokens.py:347"}
com.supertokens {"t": "2022-05-06T07:58:52.551Z", "sdkVer": "0.7.0", "message": "getSession: Started", "file": "recipe/session/recipe_implementation.py:134"}
com.supertokens {"t": "2022-05-06T07:58:52.551Z", "sdkVer": "0.7.0", "message": "getSession: rid in header: False", "file": "recipe/session/recipe_implementation.py:138"}
com.supertokens {"t": "2022-05-06T07:58:52.551Z", "sdkVer": "0.7.0", "message": "getSession: request method: GET", "file": "recipe/session/recipe_implementation.py:139"}
com.supertokens {"t": "2022-05-06T07:58:52.552Z", "sdkVer": "0.7.0", "message": "getSession: Value of doAntiCsrfCheck is: False", "file": "recipe/session/recipe_implementation.py:162"}
com.supertokens {"t": "2022-05-06T07:58:52.552Z", "sdkVer": "0.7.0", "message": "errorHandler: Started", "file": "supertokens.py:393"}
com.supertokens {"t": "2022-05-06T07:58:52.552Z", "sdkVer": "0.7.0", "message": "errorHandler: Error is from SuperTokens recipe. Message: invalid jwt", "file": "supertokens.py:394"}
srcpi
05/06/2022, 7:59 AMcom.supertokens {"t": "2022-05-06T07:58:52.552Z", "sdkVer": "0.7.0", "message": "errorHandler: Checking recipe for match: session", "file": "supertokens.py:403"}
com.supertokens {"t": "2022-05-06T07:58:52.552Z", "sdkVer": "0.7.0", "message": "errorHandler: Matched with recipeID: session", "file": "supertokens.py:406"}
com.supertokens {"t": "2022-05-06T07:58:52.552Z", "sdkVer": "0.7.0", "message": "errorHandler: returning TRY_REFRESH_TOKEN", "file": "recipe/session/recipe.py:152"}
com.supertokens {"t": "2022-05-06T07:58:52.552Z", "sdkVer": "0.7.0", "message": "Sending response to client with status code: 401", "file": "utils.py:116"}
srcpi
05/06/2022, 8:00 AMrp_st
05/06/2022, 8:04 AMrp_st
05/06/2022, 8:04 AMrp_st
05/06/2022, 8:08 AMadmin_client.cookies = profile_permission
srcpi
05/06/2022, 8:37 AMadmin_client.cookies
i receinve an errorrp_st
05/06/2022, 8:37 AMrp_st
05/06/2022, 8:37 AMsrcpi
05/06/2022, 8:37 AMtests/organization/staff/test_permissions.py:120:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.9/site-packages/django/test/client.py:747: in get
response = super().get(path, data=data, secure=secure, **extra)
venv/lib/python3.9/site-packages/django/test/client.py:396: in get
return self.generic('GET', path, secure=secure, **{
venv/lib/python3.9/site-packages/django/test/client.py:473: in generic
return self.request(**r)
venv/lib/python3.9/site-packages/django/test/client.py:704: in request
environ = self._base_environ(**request)
venv/lib/python3.9/site-packages/django/test/client.py:336: in _base_environ
'HTTP_COOKIE': '; '.join(sorted(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <dict_valueiterator object at 0x7fd7b9909db0>
'HTTP_COOKIE': '; '.join(sorted(
> '%s=%s' % (morsel.key, morsel.coded_value)
for morsel in self.cookies.values()
)),
'PATH_INFO': '/',
'REMOTE_ADDR': '127.0.0.1',
'REQUEST_METHOD': 'GET',
'SCRIPT_NAME': '',
'SERVER_NAME': 'testserver',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.1',
'wsgi.version': (1, 0),
'wsgi.url_scheme': 'http',
'wsgi.input': FakePayload(b''),
'wsgi.errors': self.errors,
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
**self.defaults,
**request,
}
E AttributeError: 'dict' object has no attribute 'key'
rp_st
05/06/2022, 8:38 AMsrcpi
05/06/2022, 8:38 AMrp_st
05/06/2022, 8:40 AMrp_st
05/06/2022, 8:40 AMsrcpi
05/06/2022, 9:11 AMrp_st
05/06/2022, 9:12 AMsrcpi
05/06/2022, 9:12 AMsrcpi
05/06/2022, 9:12 AMrp_st
05/06/2022, 9:12 AMsrcpi
05/06/2022, 9:13 AMsrcpi
05/06/2022, 9:14 AMpython
# Finish sign in/up process with passwordless
request_consume = async_rf.post('/auth/signinup/code/consume',
{'preAuthSessionId': pre_auth_session_id,
'deviceId': device_id,
'userInputCode': otp},
content_type='application/json')
temp = my_middleware(request_consume) # A coroutine
response = await temp
cookies = get_cookies(response)
print("RESPONSE AFTER API CONSUME - ", response, response.__dict__, '\n\n', cookies)
request_view = async_rf.get(reverse('staff-on-leave-list', kwargs={'organization_pk': organization.id,
'workplace_pk': workplace.id}))
request_view.COOKIES["sRefreshToken"] = cookies['sRefreshToken']['value']
request_view.COOKIES["sIdRefreshToken"] = cookies['sIdRefreshToken']['value']
# request_view.META['HTTP_ANTI_CSRF'] = response.headers['anti-csrf']
temp = my_middleware(request_view) # A coroutine
response = await temp
srcpi
05/06/2022, 9:14 AMsrcpi
05/06/2022, 9:15 AMmy_middleware = middleware(create_new_session_view)
is using such create_new_session
python
async def create_new_session_view(_: HttpRequest):
pass
srcpi
05/06/2022, 9:16 AMrp_st
05/06/2022, 9:27 AMcookies
?srcpi
05/06/2022, 9:55 AM{'sAccessToken': {'value': 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsInZlcnNpb24iOiIyIn0%3D.eyJzZXNzaW9uSGFuZGxlIjoiZmM0YmNiN2ItNzQ1MS00YTE0LThlOTYtMjNmNmI1YzQ0OGRiIiwidXNlcklkIjoiMGYwMDdiMTUtODgzMS00MjhmLWEzZGUtNzFlNDI5M2RkNWVhIiwicmVmcmVzaFRva2VuSGFzaDEiOiI5MzA0ZjU3MzM4YTNmYzQ0NTA1OTVmNGExYzk3NTRkZmE3ZjQ1ZjEwNDQ2Yjc1ODEyY2ZjYmQ1ODliNjg4NGY1IiwidXNlckRhdGEiOnsicm9sZXMiOiJzdHJpbmcifSwiZXhwaXJ5VGltZSI6MTY1MTgzNDUzMzY0NSwidGltZUNyZWF0ZWQiOjE2NTE4MzA5MzM2NDUsImxtcnQiOjE2NTE4MzA5MzM2NDR9.UiiuAtKkhIp3p%2B/l%2Bwx6hA%2B5vRbnZmKiIftALuRM5Jp4WPXGA8WHwNesMTgNNiQeYOiFhoI/VQXSgTvJsk5AnFr4kZzajLIYYmlyctW%2BJbGDOuIrd4rw3sEO7t%2BNY0YwXD%2BziBTOjfYNwvQe2jYa4ARsleK2YSssu0M6nkntNEVE0ahfaYyHNUb6HhHX/q6vxzyYvnSdGqHRFxmfFkC2bhA6Vw0tK2PlRrmuC0Ba%2B07C1kPYs8uew/5u2YM%2B0wRSv9H%2BUtZRJI625Dvyl09w3z2hQlo8WVnAFKrbrp/g70Fm9wU0Pveuvz8MQ2/phUTN5Uhux6lAqdil96LAu5RLFQ%3D%3D', 'name': 'sAccessToken', 'expires': 'Friday, May 06, 2022 15:55:34', 'path': '/', 'comment': '', 'domain': '0.0', 'max-age': '', 'secure': None, 'httponly': True, 'version': '', 'samesite': 'lax'}, 'sRefreshToken': {'value': 'vWDmcvhvM03NCqgpbU4kTpqsn0csGXBIL%2BknX/gNeNX9q%2BxL17EKnMK6utYyRO9qv5aXtAJk%2BLG/VsWzM/Ajb19j3yVIACCA3zbnJdwnnaK/LeuKok8tpFp0paHStBbI4JznTAgBEUbt%2BZ1Er8H9fOMxs%2BnRaNmiuf4PWQJeDpcdgv2OZ2aVfudNzDiPBzkYii6bcAJmUs4x4nFr5PB7ctsI01EzxegKNJmoWgfgoxT9QxCXZHQk04xWYVkFNHag%2BJoghAEYrMNNYMtHzhHy.4326b2b8a7714a00f67fedf543aa1cc125f4ea8ecdb89270a166a4b7e8a3e052.V2', 'name': 'sRefreshToken', 'expires': 'Sunday, August 14, 2022 14:55:34', 'path': '/auth/session/refresh', 'comment': '', 'domain': '0.0', 'max-age': '', 'secure': None, 'httponly': True, 'version': '', 'samesite': 'lax'}, 'sIdRefreshToken': {'value': '87d11d50-4ca4-4eb6-9bdf-e7975f42633c', 'name': 'sIdRefreshToken', 'expires': 'Sunday, August 14, 2022 14:55:34', 'path': '/', 'comment': '', 'domain': '0.0', 'max-age': '', 'secure': None, 'httponly': True, 'version': '', 'samesite': 'lax'}}
rp_st
05/06/2022, 10:30 AMrp_st
05/06/2022, 10:31 AMsrcpi
05/06/2022, 10:31 AMrp_st
05/06/2022, 10:31 AMrp_st
05/06/2022, 10:32 AMsrcpi
05/06/2022, 10:32 AMsrcpi
05/06/2022, 10:56 AMsrcpi
05/06/2022, 1:19 PM@method_decorator(verify_session(), name='dispatch')
for class based views
my test function - https://discord.com/channels/603466164219281420/969488117474132038/972035702084743179srcpi
05/06/2022, 1:21 PMadmin_client.cookies
the loggs are like this
com.supertokens {"t": "2022-05-06T13:03:43.519Z", "sdkVer": "0.7.0", "message": "getSession: Value of doAntiCsrfCheck is: False", "file": "recipe/session/recipe_implementation.py:162"}
...
com.supertokens {"t": "2022-05-06T13:03:43.519Z", "sdkVer": "0.7.0", "message": "errorHandler: Error is from SuperTokens recipe. Message: invalid jwt", "file": "supertokens.py:394"}
...
com.supertokens {"t": "2022-05-06T13:03:43.520Z", "sdkVer": "0.7.0", "message": "errorHandler: returning TRY_REFRESH_TOKEN", "file": "recipe/session/recipe.py:152"}
com.supertokens {"t": "2022-05-06T13:03:43.520Z", "sdkVer": "0.7.0", "message": "Sending response to client with status code: 401", "file": "utils.py:116"}
srcpi
05/06/2022, 1:23 PMadmin_client.session.cookies
i get something like this
...
com.supertokens {"t": "2022-05-06T13:23:15.053Z", "sdkVer": "0.7.0", "message": "getSession: UNAUTHORISED because idRefreshToken from cookies is undefined", "file": "recipe/session/recipe_implementation.py:146"}
com.supertokens {"t": "2022-05-06T13:23:15.053Z", "sdkVer": "0.7.0", "message": "errorHandler: Error is from SuperTokens recipe. Message: Session does not exist. Are you sending the session tokens in the request as cookies?", "file": "supertokens.py:394"}
...
com.supertokens {"t": "2022-05-06T13:23:15.054Z", "sdkVer": "0.7.0", "message": "errorHandler: returning UNAUTHORISED", "file": "recipe/session/recipe.py:147"}
com.supertokens {"t": "2022-05-06T13:23:15.054Z", "sdkVer": "0.7.0", "message": "Sending response to client with status code: 401", "file": "utils.py:116"}
i might have expressed not clearly enough to describe the issue, so feel free to ask for more context if something isn't clearkakashi_44
05/07/2022, 10:56 AMpython
reverse('staff-on-leave-list', kwargs={'organization_pk': organization.id,
'workplace_pk': workplace.id})
how is the view function defined?srcpi
05/10/2022, 4:44 AMpython
@method_decorator(verify_session(), name='dispatch')
class StaffOnLeaveViewSet(mixins.CreateModelMixin, mixins.DestroyModelMixin,
viewsets.ReadOnlyModelViewSet):
serializer_class = StaffOnLeaveSerializer
def get_queryset(self):
return StaffOnLeave.objects.filter(is_active=True, organization_id=self.kwargs.get("workplace_pk"))
def get_permissions(self):
if self.action in ['destroy', 'create']:
self.permission_classes = [StaffOnLeaveCreatePermission]
else:
self.permission_classes = []
return super().get_permissions()
@extend_schema(
summary="List all staff on leave",
)
def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)
# other view methods
)
kakashi_44
05/10/2022, 6:34 AMsrcpi
05/10/2022, 6:35 AMpython
from supertokens_python.recipe.session.framework.django.syncio import verify_session
sattvikc
05/10/2022, 9:28 AMsrcpi
05/10/2022, 9:29 AMsrcpi
05/10/2022, 9:32 AMsattvikc
05/10/2022, 9:33 AMsrcpi
05/10/2022, 10:41 AMpython
def test_client(cookies, client, instances):
organization, profile = instances
client.cookies = SimpleCookie(cookies)
response = client.get(reverse('staff-on-leave-list',
kwargs={'organization_pk': organization.id}))
srcpi
05/10/2022, 10:43 AMsrcpi
05/11/2022, 5:33 AMpython
client.cookies = SimpleCookie()
client.cookies["sAccessToken"] = cookies['sAccessToken']['value']
client.cookies["sRefreshToken"] = cookies['sRefreshToken']['value']
client.cookies["sIdRefreshToken"] = cookies['sIdRefreshToken']['value']
response = client.get(url)
srcpi
05/11/2022, 5:40 AMpython
def get_cookies(response: HttpResponse) -> Dict[str, Any]:
cookies: Dict[str, Any] = {}
for key, morsel in response.cookies.items():
cookies[key] = {
'value': morsel.value,
'name': key
}
for k, v in morsel.items():
if (k in ('secure', 'httponly')) and v == '':
cookies[key][k] = None
elif k == 'samesite':
if len(v) > 0 and v[-1] == ',':
v = v[:-1]
cookies[key][k] = v
else:
cookies[key][k] = v
return cookies
that generated redundant values and nesting like there https://discord.com/channels/603466164219281420/969488117474132038/971397399367012352srcpi
05/11/2022, 5:47 AM<SimpleCookie: sAccessToken='token' sIdRefreshToken='token' sRefreshToken='token'>
srcpi
05/11/2022, 5:49 AMget_cookies
function and getting cookies from cookies = response.cookies
we can just client.cookeis = cookies
srcpi
05/12/2022, 5:15 AMPOST /signinup/consume
returns user_id different from which I logged in?
python
def cookies(admin_client, async_rf, rf, client, profile):
def create_new_session_view(_: HttpRequest):
pass
print("MY USER ID", profile.supertokens_user_id, profile.phone_number)
# Start passwordless login
my_middleware = middleware(create_new_session_view)
request_login = rf.post('/auth/signinup/code',
{'phoneNumber': profile.phone_number}, content_type='application/json')
response = my_middleware(request_login)
print("SIGNINUP ", response._container)
assert response.status_code == status.HTTP_200_OK
response_content = json.loads(response._container[0].decode('utf-8'))
device_id = response_content['deviceId']
pre_auth_session_id = response_content['preAuthSessionId']
with open(TEST_OTP_LOCATION_PATH, "r") as otp_file:
otp = otp_file.read()
# Finish sign in/up process with passwordless
request_consume = rf.post('/auth/signinup/code/consume',
{'preAuthSessionId': pre_auth_session_id,
'deviceId': device_id,
'userInputCode': otp},
content_type='application/json')
response = my_middleware(request_consume)
print("CONSUME ", response._container)
assert response.status_code == status.HTTP_200_OK
return response.cookies
srcpi
05/12/2022, 5:15 AMMY USER ID db6be225-3561-428a-93ee-7a815303cfcb +998999999999
OTP {'phone_number': '+998999999999', 'code_life_time': 900000, 'pre_auth_session_id': 'DmGNaiG-4oYBGmLCDZjyF-EveVgVKIXK8RAq_vzfaUU=', 'user_input_code': '376488', 'url_with_link_code': None}
SIGNINUP [b'{"status":"OK","deviceId":"3rele/+Jg0Tyv8OsrlW1SZasU/LCKJRhuFmOaAVliNA=","preAuthSessionId":"DmGNaiG-4oYBGmLCDZjyF-EveVgVKIXK8RAq_vzfaUU=","flowType":"USER_INPUT_CODE"}']
CONSUME [b'{"status":"OK","createdNewUser":false,"user":{"id":"309b83e5-8d0a-4bca-8583-7ab229df587f","time_joined":1652275238532,"phoneNumber":"+998999999999"}}']
rp_st
05/12/2022, 5:20 AMsrcpi
05/12/2022, 5:39 AMrp_st
05/12/2022, 5:40 AMrp_st
05/12/2022, 5:41 AMsrcpi
05/12/2022, 5:41 AMsrcpi
05/12/2022, 5:41 AMsrcpi
05/12/2022, 7:03 AMrp_st
05/12/2022, 7:04 AMsrcpi
05/12/2022, 7:04 AMsrcpi
05/12/2022, 7:04 AMsrcpi
05/12/2022, 7:05 AMrp_st
05/12/2022, 7:36 AMrp_st
05/12/2022, 7:36 AMsrcpi
05/12/2022, 9:48 AMsrcpi
05/12/2022, 9:50 AMrp_st
05/12/2022, 9:51 AMsrcpi
05/12/2022, 9:51 AMrp_st
05/12/2022, 9:51 AMrp_st
05/12/2022, 9:51 AMsrcpi
05/12/2022, 9:52 AMdocker run \
-p 3567:3567 \
-e POSTGRESQL_CONNECTION_URI="postgresql://username:pass@host/dbName" \
-d registry.supertokens.io/supertokens/supertokens-postgresql
# OR
docker run \
-p 3567:3567 \
-e POSTGRESQL_USER="username" \
-e POSTGRESQL_PASSWORD="password" \
-e POSTGRESQL_HOST="host" \
-e POSTGRESQL_PORT="5432" \
-e POSTGRESQL_DATABASE_NAME="supertokens" \
-d registry.supertokens.io/supertokens/supertokens-postgresql
https://supertokens.com/docs/passwordless/quick-setup/database-setup/postgresql#:~:text=to%200.0.0.0.-,docker%20run%20%5C,%2Dd%20registry.supertokens.io/supertokens/supertokens%2Dpostgresql,-Copyrp_st
05/12/2022, 9:53 AMsrcpi
05/12/2022, 9:53 AMdocker run --name supertokens -p 3567:3567 -e POSTGRESQL_USER=postgres -e POSTGRESQL_PASSWORD=postgres -e POSTGRESQL_DATABASE_NAME=postgres -e POSTGRESQL_HOST=host.docker.internal -e POSTGRESQL_PORT=54355 --restart=always -d registry.supertokens.io/supertokens/supertokens-postgresql
rp_st
05/12/2022, 9:53 AMrp_st
05/12/2022, 9:53 AMsrcpi
05/12/2022, 9:53 AMrp_st
05/12/2022, 9:53 AMsrcpi
05/12/2022, 9:54 AMdocker run --name db_postgres -d -e POSTGRESQL_USERNAME=postgres -e POSTGRESQL_PASSWORD=postgres -e POSTGRESQL_DATABASE=postgres --restart=always -p 54355:5432 bitnami/postgresql:14
rp_st
05/12/2022, 9:54 AMrp_st
05/12/2022, 9:54 AMrp_st
05/12/2022, 9:55 AMrp_st
05/12/2022, 9:55 AMsrcpi
05/12/2022, 9:56 AMsrcpi
05/12/2022, 9:56 AMsrcpi
05/12/2022, 9:57 AMtest_<original_table_name>
, i.e. creating test tables for tests by prefixing with test_
srcpi
05/12/2022, 9:58 AMrp_st
05/12/2022, 9:58 AMrp_st
05/12/2022, 9:58 AMsrcpi
05/12/2022, 10:01 AMsrcpi
05/12/2022, 10:01 AMrp_st
05/12/2022, 10:02 AMPOSTGRESQL_TABLE_NAMES_PREFIX
rp_st
05/12/2022, 10:02 AMPOSTGRESQL_TABLE_NAMES_PREFIX="test_"
rp_st
05/12/2022, 10:02 AMsrcpi
05/12/2022, 10:03 AMrp_st
05/12/2022, 10:03 AMsrcpi
05/12/2022, 10:03 AMrp_st
05/12/2022, 10:03 AMsrcpi
05/12/2022, 10:15 AMsrcpi
05/12/2022, 10:16 AMpasswordless_users
table and I create in myapp_profile
tablesrcpi
05/12/2022, 10:18 AMpasswordless_users
tablerp_st
05/12/2022, 10:30 AM