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
Copy file name to clipboardExpand all lines: README.md
+19-14Lines changed: 19 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,12 @@
10
10
11
11
---
12
12
13
-
FastAPI extension that provides PASETO (**P**lastform-**A**gnostic **SE**curity **TO**kens) Auth support\
14
-
PASETO are a simpler, yet more secure alternative to JWTs.
13
+
FastAPI extension that provides PASETO (**P**latform-**A**gnostic **SE**curity **TO**kens) Auth support.
14
+
PASETO tokens are a simpler, yet more secure alternative to JWTs.
15
15
16
-
If you were familiar with flask-jwt-extended or fastapi-jwt-auth this extension suitable for you, as this is forked from fastapi-jwt-auth which in turn used flask-jwt-extended as motivation
16
+
If you are familiar with `flask-jwt-extended` or `fastapi-jwt-auth`, this
17
+
extension should feel familiar. It is forked from `fastapi-jwt-auth`, which in
18
+
turn was inspired by `flask-jwt-extended`.
17
19
18
20
## Features
19
21
- Access tokens and refresh tokens
@@ -25,12 +27,18 @@ If you were familiar with flask-jwt-extended or fastapi-jwt-auth this extension
25
27
- Custom token types
26
28
27
29
## Installation
28
-
The easiest way to start working with this extension with pip
30
+
31
+
This project is not published on PyPI. Install it from an immutable Git tag or
You may want to store additional information in the access token or refresh token that you can later access in the protected views.
1
+
You can store additional information in access, refresh, or custom tokens and
2
+
read it later from protected endpoints.
3
+
4
+
Pass a dictionary through the `user_claims` parameter of
5
+
`create_access_token()`, `create_refresh_token()`, or `create_token()`, then
6
+
read it back with `get_token_payload()`.
7
+
8
+
Storing data in tokens can reduce repeated database lookups, but you still need
9
+
to choose those claims carefully.
10
+
11
+
When using the `public` purpose, the token payload is signed but not encrypted.
12
+
Anyone with the token can read its contents, so do not store sensitive
13
+
information there. Whether `local` tokens are appropriate for sensitive data is
14
+
still your own security decision.
2
15
3
-
This can be done easily by passion additional information as a dictionary to the parameter **user_claims** in the functions **create_access_token()** or **create_refresh_token()**, and the data can be accessed later in a protected endpoint with the **get_token_payload()** function.
4
16
5
-
Storing data in the tokens can be good for performance.\
6
-
If you store data in the tokens, you won't need to look it up from disk/DB next time you need it in a protected endpoint.\
7
-
However, you might need to take care of what data you put in the tokens.
8
-
9
-
**Note**: When using the "public" purpose of PASETO tokens, the data in the token will merely be signed, but not encrypted. This means anyone with access to the token can freely read it's contents.\
10
-
Hence, do not store sensitive information in public tokens. Whether you trust local (encrypted) PASETO tokens to keep sensitive information is up to your own discretion.
Copy file name to clipboardExpand all lines: docs/advanced-usage/bigger-app.md
+9-6Lines changed: 9 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,9 @@
1
-
Because *fastapi-paseto* configures your setting via a class state that applies across all instances of the class, you only need to make sure to call **load_config**(callback) before declaring any endpoint. Thanks to `FastAPI` when you make an endpoint from `APIRouter` it will actually work as if everything was the same single app.
2
-
3
-
So you only need to define **load_config**(callback) where your `FastAPI` instance is created or you can import it where you include all the routers.
1
+
Because *fastapi-paseto* stores configuration on class state shared by all
2
+
`AuthPASETO` instances, you only need to call `load_config()` once before your
3
+
routes start handling requests.
4
+
5
+
In a larger FastAPI application, that usually means loading the config in the
6
+
module that creates the main `FastAPI` app and then importing routers normally.
4
7
5
8
## An example file structure
6
9
@@ -17,19 +20,19 @@ Let's say you have a file structure like this:
Copy file name to clipboardExpand all lines: docs/advanced-usage/expiry_time.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,10 @@
1
-
You can also change the expiry time for a token via parameter **expires_time** in the **create_access_token()** or **create_refresh_token()** function. This takes a *datetime.timedelta*, *datetime.datetime*, *integer*, or even *boolean* and overrides the `authpaseto_access_token_expires` and `authpaseto_refresh_token_expires` settings. This can be useful if you have different use cases for different tokens.
1
+
You can override the default token lifetime with the `expires_time` parameter on
2
+
`create_access_token()`, `create_refresh_token()`, or `create_token()`.
3
+
4
+
`expires_time` accepts a `datetime.timedelta`, `datetime.datetime`, integer
5
+
seconds, or `False`. That override takes precedence over the configured
6
+
`authpaseto_access_token_expires`, `authpaseto_refresh_token_expires`, or
It feels incomplete if there is no documentation because *fastapi-paseto* uses starlette requests directly to get headers, you must manually generate the documentation. Thanks to `FastAPI` you can generate doc easily via `Extending OpenAPI`.
1
+
Because *fastapi-paseto* reads request data directly from Starlette request and
2
+
websocket objects, FastAPI will not automatically describe those auth inputs in
3
+
OpenAPI for you. If you want the generated docs to show the header or body
You can specify which purpose you would like to use for a PASETO by using the **purpose** parameter in **create_access_token()** or **create_refresh_token()**.
1
+
You can choose the PASETO purpose used to create a token through the `purpose`
2
+
parameter of `create_access_token()`, `create_refresh_token()`, or
3
+
`create_token()`.
2
4
3
5
Please read up on PASETO tokens to find out which is the best purpose for your use case, but to put it short:
4
6
5
-
**Local** purpose means the token will be encrypted using symmetric encryption. Data in the token will not be accessible to people that get the token without also knowing your secret key.\
6
-
This is useful if the token is used in an environment where every party that needs access to the token's contents is a secure environment under your control that you can share the secret key with.
7
+
**Local** means the token is encrypted with symmetric cryptography. Someone who
8
+
obtains the token cannot read its contents without the shared secret key.
9
+
This is a good fit when every party that needs to decrypt the token is under
10
+
your control.
11
+
12
+
**Public** means the token is signed with your private key but not encrypted.
13
+
The payload remains visible to anyone holding the token, so you should not put
14
+
confidential data into public tokens. Public tokens can be verified with the
15
+
matching public key, which is safe to share with untrusted parties.
7
16
8
-
**Public** purpose means the token will not be encrypted, and instead will only be signed using your private key.
9
-
The data in the key **will be visible to everyone that gets ahold of the key**, and you should not put any confidential or sensitive data into public keys.
10
-
The key can then be validated using your public key, which is safe to share with not-trusted parties.
0 commit comments