Skip to content

Commit 422fe87

Browse files
committed
update README
2 parents 0b09d12 + 975028e commit 422fe87

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,8 @@ assert api.session == session
11521152
## Token and Authorization Requests serialization
11531153

11541154
If you implement a web application, you will most likely need to serialize access tokens inside the user session.
1155-
To make it easier, `requests_oauth2client` provides several classes that implement (de)serialization.
1155+
To make it easier, `requests_oauth2client` provides several classes that implement (de)serialization of `BearerToken`,
1156+
'DPoPToken', `AuthorizationRequest` (and derivates) and `DPoPKey` to `bytes`.
11561157

11571158
```python
11581159
from requests_oauth2client import BearerToken, TokenSerializer
@@ -1162,9 +1163,9 @@ token_serializer = TokenSerializer()
11621163
bearer_token = BearerToken("access_token", expires_in=60) # here is a sample token
11631164
serialized_value = token_serializer.dumps(bearer_token)
11641165
print(serialized_value)
1165-
# q1ZKTE5OLS6OL8nPTs1TskLl6iilVhRkFqUWxyeWKFkZmpsZWFiYmJqZ6iiB5eNLKgtSlayUnFITi1KLlGoB
1166-
# you can store that string value in session or anywhere needed
1167-
# beware, this is clear-text!
1166+
# b'q1ZKTE5OLS6OL8nPTs1TskLl6iilVhRkFqUWxyeWKFkZmpsZWFiYmJqZ6iiB5eNLKgtSlayUnFITi1KLlGoB'
1167+
# you can store that value in session or anywhere needed
1168+
# beware, this is decodable clear-text!
11681169

11691170
# loading back the token to a BearerToken instance
11701171
deserialized_token = token_serializer.loads(serialized_value)
@@ -1229,9 +1230,9 @@ def custom_loader(serialized: bytes) -> dict[str, Any]:
12291230

12301231
token_serializer = TokenSerializer(make_instance=custom_make_instance, dumper=custom_dumper, loader=custom_loader)
12311232

1232-
my_custom_token = CustomToken(**{"token_type": "CustomToken", "access_token": "..."})
1233+
my_custom_token = CustomToken(token_type="CustomToken", access_token="...")
12331234
serialized = token_serializer.dumps(my_custom_token)
1234-
assert serialized == b'eyJhY2Nlc3NfdG9rZW4iOiAiLi4uIiwgInRva2VuX3R5cGUiOiAiQ3VzdG9tVG9rZW4ifQ=='
1235+
assert serialized == b"eyJhY2Nlc3NfdG9rZW4iOiAiLi4uIiwgInRva2VuX3R5cGUiOiAiQ3VzdG9tVG9rZW4ifQ=="
12351236
assert token_serializer.loads(serialized) == my_custom_token
12361237
```
12371238

0 commit comments

Comments
 (0)