You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"binding_code": "123456"# Code user received via SMS/Email
317
+
"binding_code": "123456", # Code user received via SMS/Email
318
+
"persist": True, # Persist tokens to session store
319
+
"audience": "https://api.example.com", # Required when persist=True
320
+
"scope": "openid profile email"# Optional scope
315
321
})
316
322
317
323
access_token = verify_response.access_token
318
324
id_token = verify_response.id_token
319
-
token_type = verify_response.token_type
320
325
321
326
print(f"MFA verification successful!")
322
327
print(f"Access Token: {access_token}")
323
328
print(f"ID Token: {id_token}")
329
+
print("Tokens have been persisted to session store")
324
330
325
331
exceptExceptionas error:
326
332
print(f"Verification failed: {error}")
327
333
```
328
334
335
+
> [!NOTE]
336
+
> Setting `persist=True` automatically updates the session store with the new tokens, similar to nextjs-auth0 and auth0-spa-js SDKs. This eliminates the need for manual token management after MFA verification.
337
+
329
338
### Verify with OTP
330
339
331
340
```python
332
341
try:
333
342
verify_response =await server_client.mfa.verify({
334
343
"mfa_token": mfa_token,
335
-
"otp": "123456"# 6-digit code from authenticator app
344
+
"otp": "123456", # 6-digit code from authenticator app
345
+
"persist": True, # Persist tokens to session store
346
+
"audience": "https://api.example.com", # Required when persist=True
347
+
"scope": "openid profile email"
336
348
})
337
349
338
350
access_token = verify_response.access_token
339
-
id_token = verify_response.id_token
340
351
341
352
print("MFA verification successful!")
353
+
print("Tokens have been persisted to session store")
342
354
343
355
exceptExceptionas error:
344
356
print(f"Invalid OTP code: {error}")
@@ -352,17 +364,64 @@ Recovery codes can be used to complete MFA verification without initiating a cha
352
364
try:
353
365
verify_response =await server_client.mfa.verify({
354
366
"mfa_token": mfa_token,
355
-
"recovery_code": "XXXX-XXXX-XXXX"# One of the recovery codes
367
+
"recovery_code": "XXXX-XXXX-XXXX", # One of the recovery codes
368
+
"persist": True, # Persist tokens to session store
369
+
"audience": "https://api.example.com"# Required when persist=True
356
370
})
357
371
358
372
access_token = verify_response.access_token
359
373
360
374
print("MFA verification successful using recovery code!")
375
+
print("Tokens have been persisted to session store")
361
376
362
377
exceptExceptionas error:
363
378
print(f"Verification failed: {error}")
364
379
```
365
380
381
+
## Session Persistence
382
+
383
+
By default, `verify()` returns tokens without persisting them to the session store. However, you can automatically persist tokens by setting `persist=True`, similar to how nextjs-auth0 and auth0-spa-js handle MFA.
384
+
385
+
### Automatic Session Update
386
+
387
+
When you set `persist=True`, the SDK will:
388
+
1. Update the session's `access_token` for the specified audience
389
+
2. Update the session's `id_token` if present
390
+
3. Add the token to the `token_sets` array with expiration information
391
+
392
+
```python
393
+
verify_response =await server_client.mfa.verify({
394
+
"mfa_token": mfa_token,
395
+
"otp": "123456",
396
+
"persist": True, # Enable automatic persistence
397
+
"audience": "https://api.example.com", # Required when persist=True
398
+
"scope": "openid profile email"# Optional
399
+
})
400
+
401
+
# Tokens are now available in the session store
402
+
# User can call server_client.get_user() to access updated session
403
+
user =await server_client.get_user()
404
+
```
405
+
406
+
### Manual Session Update
407
+
408
+
If you prefer to manage session updates yourself:
409
+
410
+
```python
411
+
verify_response =await server_client.mfa.verify({
412
+
"mfa_token": mfa_token,
413
+
"otp": "123456"
414
+
# persist=False (default)
415
+
})
416
+
417
+
# Handle token storage manually if needed
418
+
access_token = verify_response.access_token
419
+
id_token = verify_response.id_token
420
+
421
+
# Store tokens in your application's session management
0 commit comments