Skip to content

Commit 0226085

Browse files
committed
fix: auth react tests
1 parent 2685c31 commit 0226085

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

tests/auth-react/django3x/mysite/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
emailpassword,
1111
emailverification,
1212
multifactorauth,
13+
oauth2provider,
1314
passwordless,
1415
session,
1516
thirdparty,
@@ -40,6 +41,8 @@
4041
APIOptions as EVAPIOptions,
4142
)
4243
from supertokens_python.recipe.jwt import JWTRecipe
44+
from supertokens_python.recipe.oauth2provider.recipe import OAuth2ProviderRecipe
45+
from supertokens_python.recipe.openid.recipe import OpenIdRecipe
4346
from supertokens_python.recipe.passwordless import (
4447
ContactEmailOnlyConfig,
4548
ContactEmailOrPhoneConfig,
@@ -315,6 +318,8 @@ def custom_init():
315318
Supertokens.reset()
316319
TOTPRecipe.reset()
317320
MultiFactorAuthRecipe.reset()
321+
OpenIdRecipe.reset()
322+
OAuth2ProviderRecipe.reset()
318323

319324
def override_email_verification_apis(
320325
original_implementation_email_verification: EmailVerificationAPIInterface,
@@ -942,6 +947,10 @@ async def resync_session_and_fetch_mfa_info_put(
942947
)
943948
),
944949
},
950+
{
951+
"id": "oauth2provider",
952+
"init": oauth2provider.init(),
953+
},
945954
]
946955

947956
accountlinking_config_input: Dict[str, Any] = {
@@ -1002,7 +1011,7 @@ async def should_do_automatic_account_linking(
10021011
supertokens_config=SupertokensConfig("http://localhost:9000"),
10031012
app_info=InputAppInfo(
10041013
app_name="SuperTokens Demo",
1005-
api_domain="0.0.0.0:" + get_api_port(),
1014+
api_domain="localhost:" + get_api_port(),
10061015
website_domain=get_website_domain(),
10071016
),
10081017
framework="django",

tests/auth-react/django3x/polls/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
name="setEnabledRecipes",
3636
),
3737
path("test/getTOTPCode", views.test_get_totp_code, name="getTotpCode"), # type: ignore
38+
path("test/create-oauth2-client", views.test_create_oauth2_client, name="createOAuth2Client"), # type: ignore
3839
path("test/getDevice", views.test_get_device, name="getDevice"), # type: ignore
3940
path("test/featureFlags", views.test_feature_flags, name="featureFlags"), # type: ignore
4041
path("beforeeach", views.before_each, name="beforeeach"), # type: ignore

tests/auth-react/django3x/polls/views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
from supertokens_python.recipe.multifactorauth.asyncio import (
2828
add_to_required_secondary_factors_for_user,
2929
)
30+
from supertokens_python.recipe.oauth2provider.syncio import create_oauth2_client
31+
from supertokens_python.recipe.oauth2provider.interfaces import CreateOAuth2ClientInput
3032
from supertokens_python.recipe.session import SessionContainer
3133
from supertokens_python.recipe.session.interfaces import SessionClaimValidator
3234
from supertokens_python.recipe.thirdparty import ProviderConfig
@@ -457,6 +459,14 @@ def test_get_totp_code(request: HttpRequest):
457459
return JsonResponse({"totp": code})
458460

459461

462+
def test_create_oauth2_client(request: HttpRequest):
463+
body = json.loads(request.body)
464+
if body is None:
465+
raise Exception("Invalid request body")
466+
client = create_oauth2_client(CreateOAuth2ClientInput.from_json(body))
467+
return JsonResponse(client.to_json())
468+
469+
460470
def before_each(request: HttpRequest):
461471
import mysite.store
462472

@@ -486,6 +496,7 @@ def test_feature_flags(request: HttpRequest):
486496
"mfa",
487497
"recipeConfig",
488498
"accountlinking-fixes",
499+
"oauth2",
489500
]
490501
}
491502
)

tests/auth-react/fastapi-server/app.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from supertokens_python.recipe import (
4444
emailpassword,
4545
emailverification,
46+
oauth2provider,
4647
passwordless,
4748
session,
4849
thirdparty,
@@ -106,6 +107,10 @@
106107
AssociateUserToTenantUnknownUserIdError,
107108
TenantConfigCreateOrUpdate,
108109
)
110+
from supertokens_python.recipe.oauth2provider.interfaces import CreateOAuth2ClientInput
111+
from supertokens_python.recipe.oauth2provider.recipe import OAuth2ProviderRecipe
112+
from supertokens_python.recipe.oauth2provider.asyncio import create_oauth2_client
113+
from supertokens_python.recipe.openid.recipe import OpenIdRecipe
109114
from supertokens_python.recipe.passwordless import (
110115
ContactEmailOnlyConfig,
111116
ContactEmailOrPhoneConfig,
@@ -391,6 +396,8 @@ def custom_init():
391396
Supertokens.reset()
392397
TOTPRecipe.reset()
393398
MultiFactorAuthRecipe.reset()
399+
OpenIdRecipe.reset()
400+
OAuth2ProviderRecipe.reset()
394401

395402
def override_email_verification_apis(
396403
original_implementation_email_verification: EmailVerificationAPIInterface,
@@ -1021,6 +1028,10 @@ async def resync_session_and_fetch_mfa_info_put(
10211028
)
10221029
),
10231030
},
1031+
{
1032+
"id": "oauth2provider",
1033+
"init": oauth2provider.init(),
1034+
},
10241035
]
10251036

10261037
global accountlinking_config
@@ -1084,7 +1095,7 @@ async def should_do_automatic_account_linking(
10841095
supertokens_config=SupertokensConfig("http://localhost:9000"),
10851096
app_info=InputAppInfo(
10861097
app_name="SuperTokens Demo",
1087-
api_domain="0.0.0.0:" + get_api_port(),
1098+
api_domain="localhost:" + get_api_port(),
10881099
website_domain=get_website_domain(),
10891100
),
10901101
framework="fastapi",
@@ -1374,6 +1385,15 @@ async def test_get_totp_code(request: Request):
13741385
return JSONResponse({"totp": code})
13751386

13761387

1388+
@app.post("/test/create-oauth2-client")
1389+
async def test_create_oauth2_client(request: Request):
1390+
body = await request.json()
1391+
if body is None:
1392+
raise Exception("Invalid request body")
1393+
client = await create_oauth2_client(CreateOAuth2ClientInput.from_json(body))
1394+
return JSONResponse(client.to_json())
1395+
1396+
13771397
@app.get("/test/getDevice")
13781398
def test_get_device(request: Request):
13791399
global code_store
@@ -1397,6 +1417,7 @@ def test_feature_flags(request: Request):
13971417
"mfa",
13981418
"recipeConfig",
13991419
"accountlinking-fixes",
1420+
"oauth2",
14001421
]
14011422
return JSONResponse({"available": available})
14021423

tests/auth-react/flask-server/app.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
accountlinking,
3636
emailpassword,
3737
emailverification,
38+
oauth2provider,
3839
passwordless,
3940
session,
4041
thirdparty,
@@ -77,6 +78,10 @@
7778
delete_tenant,
7879
disassociate_user_from_tenant,
7980
)
81+
from supertokens_python.recipe.oauth2provider.syncio import create_oauth2_client
82+
from supertokens_python.recipe.oauth2provider.interfaces import CreateOAuth2ClientInput
83+
from supertokens_python.recipe.oauth2provider.recipe import OAuth2ProviderRecipe
84+
from supertokens_python.recipe.openid.recipe import OpenIdRecipe
8085
from supertokens_python.recipe.passwordless.syncio import update_user
8186
from supertokens_python.recipe.session.exceptions import (
8287
ClaimValidationError,
@@ -374,6 +379,8 @@ def custom_init():
374379
Supertokens.reset()
375380
TOTPRecipe.reset()
376381
MultiFactorAuthRecipe.reset()
382+
OpenIdRecipe.reset()
383+
OAuth2ProviderRecipe.reset()
377384

378385
def override_email_verification_apis(
379386
original_implementation_email_verification: EmailVerificationAPIInterface,
@@ -1004,6 +1011,10 @@ async def resync_session_and_fetch_mfa_info_put(
10041011
)
10051012
),
10061013
},
1014+
{
1015+
"id": "oauth2provider",
1016+
"init": oauth2provider.init(),
1017+
},
10071018
]
10081019

10091020
global accountlinking_config
@@ -1066,7 +1077,7 @@ async def should_do_automatic_account_linking(
10661077
supertokens_config=SupertokensConfig("http://localhost:9000"),
10671078
app_info=InputAppInfo(
10681079
app_name="SuperTokens Demo",
1069-
api_domain="0.0.0.0:" + get_api_port(),
1080+
api_domain="localhost:" + get_api_port(),
10701081
website_domain=get_website_domain(),
10711082
),
10721083
framework="flask",
@@ -1401,6 +1412,15 @@ def test_get_totp_code():
14011412
return jsonify({"totp": code})
14021413

14031414

1415+
@app.post("/test/create-oauth2-client") # type: ignore
1416+
def test_create_oauth2_client():
1417+
body = request.get_json()
1418+
if body is None:
1419+
raise Exception("Invalid request body")
1420+
client = create_oauth2_client(CreateOAuth2ClientInput.from_json(body))
1421+
return jsonify(client.to_json())
1422+
1423+
14041424
@app.get("/test/getDevice") # type: ignore
14051425
def test_get_device():
14061426
global code_store
@@ -1424,6 +1444,7 @@ def test_feature_flags():
14241444
"mfa",
14251445
"recipeConfig",
14261446
"accountlinking-fixes",
1447+
"oauth2",
14271448
]
14281449
return jsonify({"available": available})
14291450

0 commit comments

Comments
 (0)