From c687f9e2bd958c7260672e7b81e3f87be019e027 Mon Sep 17 00:00:00 2001 From: frankie567 Date: Thu, 30 Dec 2021 14:23:11 +0000 Subject: [PATCH] Automated deployment: Thu Dec 30 14:23:11 UTC 2021 c4de66b81cab11850307f5768aee41490af9d3cd --- 404.html | 128 +++- .../{cookie => backend}/index.html | 165 ++-- configuration/authentication/index.html | 204 ++++- .../authentication/strategies/jwt/index.html | 572 ++++++++++++++ .../strategies/redis/index.html | 571 ++++++++++++++ .../{jwt => transports/bearer}/index.html | 200 ++--- .../transports/cookie/index.html | 604 +++++++++++++++ configuration/databases/mongodb/index.html | 56 +- configuration/databases/ormar/index.html | 56 +- configuration/databases/sqlalchemy/index.html | 56 +- configuration/databases/tortoise/index.html | 56 +- configuration/full-example/index.html | 564 +++++++++++++- configuration/models/index.html | 56 +- configuration/oauth/index.html | 623 ++++++++++++++- configuration/overview/index.html | 83 +- configuration/routers/auth/index.html | 69 +- configuration/routers/index.html | 58 +- configuration/routers/register/index.html | 61 +- configuration/routers/reset/index.html | 60 +- configuration/routers/users/index.html | 60 +- configuration/routers/verify/index.html | 60 +- configuration/user-manager/index.html | 60 +- .../create-user-programmatically/index.html | 66 +- index.html | 74 +- installation/index.html | 56 +- migration/08_to_1x/index.html | 70 +- migration/1x_to_2x/index.html | 70 +- migration/2x_to_3x/index.html | 56 +- migration/3x_to_4x/index.html | 56 +- migration/4x_to_5x/index.html | 56 +- migration/6x_to_7x/index.html | 56 +- migration/7x_to_8x/index.html | 69 +- migration/8x_to_9x/index.html | 711 ++++++++++++++++++ search/search_index.json | 2 +- sitemap.xml | 82 +- sitemap.xml.gz | Bin 216 -> 218 bytes usage/current-user/index.html | 80 +- usage/flow/index.html | 219 ++++-- usage/routes/index.html | 283 ++++--- 39 files changed, 5844 insertions(+), 584 deletions(-) rename configuration/authentication/{cookie => backend}/index.html (81%) create mode 100644 configuration/authentication/strategies/jwt/index.html create mode 100644 configuration/authentication/strategies/redis/index.html rename configuration/authentication/{jwt => transports/bearer}/index.html (69%) create mode 100644 configuration/authentication/transports/cookie/index.html create mode 100644 migration/8x_to_9x/index.html diff --git a/404.html b/404.html index e04d2887..9dd5dcb8 100644 --- a/404.html +++ b/404.html @@ -436,8 +436,95 @@ + +
  • + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + +
  • + + Create a backend
  • @@ -881,6 +989,20 @@ + + + + + +
  • + + 8.x.x ➡️ 9.x.x + +
  • + + + + diff --git a/configuration/authentication/cookie/index.html b/configuration/authentication/backend/index.html similarity index 81% rename from configuration/authentication/cookie/index.html rename to configuration/authentication/backend/index.html index ecf6bce3..0214a06c 100644 --- a/configuration/authentication/cookie/index.html +++ b/configuration/authentication/backend/index.html @@ -8,7 +8,7 @@ -Cookie - FastAPI Users +Create a backend - FastAPI Users @@ -22,7 +22,7 @@
    - + Skip to content
    @@ -46,7 +46,7 @@
    - Cookie + Create a backend
    @@ -212,19 +212,64 @@ Introduction +
  • + + + +
  • +
  • + + + +
  • - Cookie + Create a backend
  • +
  • + + 8.x.x ➡️ 9.x.x + +
  • @@ -436,23 +471,8 @@ @@ -462,62 +482,39 @@
    -

    Cookie

    -

    Cookies are an easy way to store stateful information into the user browser. Thus, it is more useful for browser-based navigation (e.g. a front-end app making API requests) rather than pure API interaction.

    -

    Configuration

    -
    from fastapi_users.authentication import CookieAuthentication
    +

    Create a backend

    +

    As we said, a backend is the combination of a transport and a strategy. That way, you can create a complete strategy exactly fitting your needs.

    +

    For this, you have to use the AuthenticationBackend class.

    +
    from fastapi_users.authentication import AuthenticationBackend, BearerTransport, JWTStrategy
     
     SECRET = "SECRET"
     
    -cookie_authentication = CookieAuthentication(secret=SECRET, lifetime_seconds=3600)
    +bearer_transport = BearerTransport(tokenUrl="auth/jwt/login")
    +
    +def get_jwt_strategy() -> JWTStrategy:
    +    return JWTStrategy(secret=SECRET, lifetime_seconds=3600)
    +
    +auth_backend = AuthenticationBackend(
    +    name="jwt",
    +    transport=bearer_transport,
    +    get_strategy=get_jwt_strategy,
    +)
     

    As you can see, instantiation is quite simple. It accepts the following arguments:

      -
    • secret (Union[str, pydantic.SecretStr]): A constant secret which is used to encode the cookie. Use a strong passphrase and keep it secure.
    • -
    • lifetime_seconds (int): The lifetime of the cookie in seconds.
    • -
    • cookie_name (fastapiusersauth): Name of the cookie.
    • -
    • cookie_path (/): Cookie path.
    • -
    • cookie_domain (None): Cookie domain.
    • -
    • cookie_secure (True): Whether to only send the cookie to the server via SSL request.
    • -
    • cookie_httponly (True): Whether to prevent access to the cookie via JavaScript.
    • -
    • cookie_samesite (lax): A string that specifies the samesite strategy for the cookie. Valid values are lax, strict and none. Defaults to lax.
    • -
    • name (Optional[str]): Name of the backend. It's useful in the case you wish to have several backends of the same class. Each backend should have a unique name. Defaults to cookie.
    • +
    • name (str): Name of the backend. Each backend should have a unique name.
    • +
    • transport (Transport): An instance of a Transport class.
    • +
    • get_strategy (Callable[..., Strategy]): A dependency callable returning an instance of a Strategy class.
    -
    cookie_authentication = CookieAuthentication(
    -    secret=SECRET,
    -    lifetime_seconds=3600,
    -    name="my-cookie",
    -)
    -
    -
    -

    Tip

    -

    The value of the cookie is actually a JWT. This authentication backend shares most of its logic with the JWT one.

    -
    -

    Login

    -

    This method will return a response with a valid set-cookie header upon successful login:

    -
    -

    200 OK

    -
    -
    -

    Check documentation about login route.

    -
    -

    Logout

    -

    This method will remove the authentication cookie:

    -
    -

    200 OK

    -
    -
    -

    Check documentation about logout route.

    -
    -

    Authentication

    -

    This method expects that you provide a valid cookie in the headers.

    +

    Next steps

    +

    You can have as many authentication backends as you wish. You'll then have to pass those backends to your FastAPIUsers instance and generate an auth router for each one of them.