Skip to content

docs: Update WebAuthn documentation for Python SDK support #999

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 10 commits into
base: master
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
1 change: 1 addition & 0 deletions docs/additional-verification/mfa/important-concepts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
| Passwordless - Email magic link | `link-email` |
| Passwordless - SMS magic link | `link-phone` |
| TOTP | `totp` |
| WebAuthn (Passkeys) | `webauthn` |

Check failure on line 68 in docs/additional-verification/mfa/important-concepts.mdx

View workflow job for this annotation

GitHub Actions / vale-lint

[vale] reported by reviewdog 🐶 [SuperTokens.spelling] This word is not recognized: 'webauthn' Raw Output: {"message": "[SuperTokens.spelling] This word is not recognized: 'webauthn'", "location": {"path": "docs/additional-verification/mfa/important-concepts.mdx", "range": {"start": {"line": 68, "column": 26}}}, "severity": "ERROR"}

These factor IDs get used to configure the MFA requirements for users (except the `acccess-denied` one).
They are also used to indicate which authentication challenges have completed in the current session.
Expand Down
6 changes: 3 additions & 3 deletions docs/additional-verification/mfa/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ title: Introduction
hide_title: true
skip_llms_txt: true
description: >-
Implement multi-factor authentication with email, SMS, or TOTP, and customize
Implement multi-factor authentication with email, SMS, TOTP, or WebAuthn (Passkeys), and customize
user authentication preferences.
page_type: overview
page_type: overview
recipe: mfa
category: multi-factor-authentication
---
Expand All @@ -17,7 +17,7 @@ category: multi-factor-authentication
## Overview

Multi-factor authentication (MFA) is a security process that requires users to verify their identity through multiple forms of credentials before gaining access to a system.
**SuperTokens** allows you to integrate MFA in your application using either Email/SMS One-Time Password (OTP) or Time-based One-Time Password (TOTP).
**SuperTokens** allows you to integrate MFA in your application using Email/SMS One-Time Password (OTP), Time-based One-Time Password (TOTP), or WebAuthn (Passkeys).

## Prerequisites

Expand Down
42 changes: 26 additions & 16 deletions docs/additional-verification/mfa/protect-routes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ async def like_comment(request: HttpRequest):

The same modification can be done for `getSession` as well.

### Check MFA claim manually
### Check MFA claim manually

To account for a more complex logic when you check the MFA claim (other than checking if `v` is `true`), look over the next code snippet.

Expand Down Expand Up @@ -869,15 +869,16 @@ At the moment this feature is not supported through the Go SDK.

```python
from fastapi import Depends
from supertokens_python.recipe.session.framework.fastapi import verify_session
from supertokens_python.recipe.session.exceptions import (
raise_invalid_claims_exception,
ClaimValidationError,
)
from supertokens_python.recipe.session import SessionContainer

from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.exceptions import (
ClaimValidationError,
raise_invalid_claims_exception,
)
from supertokens_python.recipe.session.framework.fastapi import verify_session


@app.post("/update-blog") # type: ignore
Expand Down Expand Up @@ -915,10 +916,16 @@ async def update_blog_api(session: SessionContainer = Depends(verify_session()))

```python
from flask import Flask, g
from supertokens_python.recipe.session.framework.flask import verify_session

from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.exceptions import raise_invalid_claims_exception, ClaimValidationError
from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import MultiFactorAuthClaim
from supertokens_python.recipe.session.exceptions import (
ClaimValidationError,
raise_invalid_claims_exception,
)
from supertokens_python.recipe.session.framework.flask import verify_session

app = Flask(__name__)

Expand Down Expand Up @@ -952,21 +959,24 @@ def check_mfa_api():
<PythonFrameworksCard.Content value="django">

```python
from typing import cast

from django.http import HttpRequest
from supertokens_python.recipe.session.framework.django.asyncio import verify_session

from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.exceptions import (
raise_invalid_claims_exception,
ClaimValidationError,
raise_invalid_claims_exception,
)
from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
from supertokens_python.recipe.session.framework.django.asyncio import verify_session


@verify_session()
async def get_user_info_api(request: HttpRequest):
session: SessionContainer = request.supertokens # type: ignore
session: SessionContainer = cast(SessionContainer, request.supertokens) # type: ignore
# highlight-start
mfa_claim_value = await session.get_claim_value(MultiFactorAuthClaim)
if mfa_claim_value is None:
Expand Down
66 changes: 41 additions & 25 deletions docs/additional-verification/mfa/step-up-auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,19 @@ At the moment this feature is not supported through the Go SDK.
<PythonFrameworksCard.Content value="fastapi">

```python
import time

from fastapi import Depends
from supertokens_python.recipe.session.framework.fastapi import verify_session
from supertokens_python.recipe.session.exceptions import (
raise_invalid_claims_exception,
ClaimValidationError,
)
from supertokens_python.recipe.session import SessionContainer

from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
import time
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.exceptions import (
ClaimValidationError,
raise_invalid_claims_exception,
)
from supertokens_python.recipe.session.framework.fastapi import verify_session


@app.post("/update-blog") # type: ignore
Expand Down Expand Up @@ -462,12 +464,19 @@ async def update_blog_api(session: SessionContainer = Depends(verify_session()))
<PythonFrameworksCard.Content value="flask">

```python
import time

from flask import Flask, g
from supertokens_python.recipe.session.framework.flask import verify_session

from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.exceptions import raise_invalid_claims_exception, ClaimValidationError
from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import MultiFactorAuthClaim
import time
from supertokens_python.recipe.session.exceptions import (
ClaimValidationError,
raise_invalid_claims_exception,
)
from supertokens_python.recipe.session.framework.flask import verify_session

app = Flask(__name__)

Expand Down Expand Up @@ -502,22 +511,25 @@ def check_mfa_api():
<PythonFrameworksCard.Content value="django">

```python
import time
from typing import cast

from django.http import HttpRequest
from supertokens_python.recipe.session.framework.django.asyncio import verify_session

from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.exceptions import (
raise_invalid_claims_exception,
ClaimValidationError,
raise_invalid_claims_exception,
)
from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
import time
from supertokens_python.recipe.session.framework.django.asyncio import verify_session


@verify_session()
async def get_user_info_api(request: HttpRequest):
session: SessionContainer = request.supertokens # type: ignore
session: SessionContainer = cast(SessionContainer, request.supertokens) # type: ignore
# highlight-start
mfa_claim_value = await session.get_claim_value(MultiFactorAuthClaim)
assert mfa_claim_value is not None
Expand Down Expand Up @@ -639,20 +651,24 @@ At the moment this feature is not supported through the Go SDK.
<BackendTabs.TabItem value="python">

```python
from supertokens_python import init, InputAppInfo, SupertokensConfig
import time
from typing import Any, Awaitable, Callable, Dict, List

from supertokens_python import InputAppInfo, SupertokensConfig, init
from supertokens_python.recipe import multifactorauth
from supertokens_python.recipe.multifactorauth.types import FactorIds, OverrideConfig
from supertokens_python.recipe.multifactorauth.interfaces import RecipeInterface
from typing import Dict, Any, Callable, Awaitable, List
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.multifactorauth.types import MFARequirementList
from supertokens_python.recipe.multifactorauth.multi_factor_auth_claim import (
MultiFactorAuthClaim,
)
import time
from supertokens_python.recipe.multifactorauth.types import (
FactorIds,
MFARequirementList,
OverrideConfig,
)
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.exceptions import (
raise_invalid_claims_exception,
ClaimValidationError,
raise_invalid_claims_exception,
)


Expand Down
Loading
Loading