13
13
# under the License.
14
14
import json
15
15
import os
16
- from typing import Any , Dict , List , cast
16
+ from typing import Any , Dict , List
17
17
18
- # Python loader for WASM. Allows native imports
19
- import wasmtime .loader # type: ignore # noqa: F401
18
+ import httpx
20
19
from django .http import HttpRequest , HttpResponse , JsonResponse
21
20
from mysite .store import get_codes , get_url_with_token , webauthn_store
22
21
from mysite .utils import custom_init
72
71
from supertokens_python .types .auth_utils import LinkingToSessionUserFailedError
73
72
from supertokens_python .types .base import AccountInfoInput
74
73
75
- # Load the required functions from the WASM binary
76
- from ..webauthn import createAndAssertCredential , createCredential # type: ignore
77
-
78
74
mode = os .environ .get ("APP_MODE" , "asgi" )
79
75
80
76
@@ -468,6 +464,7 @@ def test_feature_flags(request: HttpRequest):
468
464
"recipeConfig" ,
469
465
"accountlinking-fixes" ,
470
466
"oauth2" ,
467
+ "webauthn" ,
471
468
]
472
469
}
473
470
)
@@ -493,113 +490,36 @@ def setup_st(request: HttpRequest):
493
490
494
491
495
492
def get_webauthn_token (request : HttpRequest ):
496
- body = json .loads (request .body )
497
- if body is None :
498
- raise Exception ("Invalid request body" )
499
-
500
- webauthn = webauthn_store .get (body ["email" ])
493
+ webauthn = webauthn_store .get (request .GET .get ("email" , "" ))
501
494
if webauthn is None :
502
495
return JsonResponse ({"error" : "Webauthn not found" }, status = 404 )
503
496
504
497
return JsonResponse ({"token" : webauthn ["token" ]})
505
498
506
499
507
- def create_credential (
508
- register_options : Dict [str , Any ],
509
- rp_id : str ,
510
- rp_name : str ,
511
- origin : str ,
512
- user_not_present : bool = True ,
513
- user_not_verified : bool = True ,
514
- ):
515
- register_options_str = json .dumps (register_options )
516
- result = createCredential ( # type: ignore
517
- register_options_str ,
518
- rp_id ,
519
- rp_name ,
520
- origin ,
521
- user_not_present ,
522
- user_not_verified ,
523
- )
524
-
525
- if result is None :
526
- raise Exception ("Failed to create credential" )
527
-
528
- try :
529
- credential = json .loads (cast (str , result ))
530
- return credential
531
- except Exception :
532
- raise Exception ("Failed to parse credential" )
533
-
534
-
535
- def create_and_assert_credential (
536
- register_options : Dict [str , Any ],
537
- sign_in_options : Dict [str , Any ],
538
- rp_id : str ,
539
- rp_name : str ,
540
- origin : str ,
541
- user_not_present : bool = True ,
542
- user_not_verified : bool = True ,
543
- ):
544
- register_options_str = json .dumps (register_options )
545
- sign_in_options_str = json .dumps (sign_in_options )
546
- result = createAndAssertCredential ( # type: ignore
547
- register_options_str ,
548
- sign_in_options_str ,
549
- rp_id ,
550
- rp_name ,
551
- origin ,
552
- user_not_present ,
553
- user_not_verified ,
554
- )
555
-
556
- if result is None :
557
- raise Exception ("Failed to create/assert credential" )
558
-
559
- try :
560
- parsed_result : Dict [str , Any ] = json .loads (cast (str , result ))
561
- return {
562
- "attestation" : parsed_result ["attestation" ],
563
- "assertion" : parsed_result ["assertion" ],
564
- }
565
- except Exception :
566
- raise Exception ("Failed to parse result" )
567
-
568
-
569
500
def webauthn_create_and_assert_credential (request : HttpRequest ):
570
501
body = json .loads (request .body )
571
502
if body is None :
572
503
raise Exception ("Invalid request body" )
573
504
574
- try :
575
- credential = create_and_assert_credential ( # type: ignore
576
- register_options = body ["registerOptionsResponse" ],
577
- sign_in_options = body ["signInOptionsResponse" ],
578
- rp_id = body ["rpId" ],
579
- rp_name = body ["rpName" ],
580
- origin = body ["origin" ],
581
- user_not_present = False ,
582
- user_not_verified = False ,
583
- )
584
- return JsonResponse ({"credential" : credential })
585
- except Exception as err :
586
- return JsonResponse ({"error" : str (err )}, status = 500 )
505
+ test_server_port = os .environ .get ("NODE_PORT" , 8082 )
506
+ response = httpx .post (
507
+ url = f"http://localhost:{ test_server_port } /test/webauthn/create-and-assert-credential" ,
508
+ json = body ,
509
+ )
510
+
511
+ return JsonResponse (response .json ())
587
512
588
513
589
514
def webauthn_create_credential (request : HttpRequest ):
590
515
body = json .loads (request .body )
591
516
if body is None :
592
517
raise Exception ("Invalid request body" )
593
518
594
- try :
595
- credential = create_credential ( # type: ignore
596
- register_options = body ["registerOptionsResponse" ],
597
- rp_id = body ["rpId" ],
598
- rp_name = body ["rpName" ],
599
- origin = body ["origin" ],
600
- user_not_present = False ,
601
- user_not_verified = False ,
602
- )
603
- return JsonResponse ({"credential" : credential })
604
- except Exception as err :
605
- return JsonResponse ({"error" : str (err )}, status = 500 )
519
+ test_server_port = os .environ .get ("NODE_PORT" , 8082 )
520
+ response = httpx .post (
521
+ url = f"http://localhost:{ test_server_port } /test/webauthn/create-credential" ,
522
+ json = body ,
523
+ )
524
+
525
+ return JsonResponse (response .json ())
0 commit comments