@@ -1152,7 +1152,8 @@ assert api.session == session
11521152## Token and Authorization Requests serialization
11531153
11541154If 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
11581159from requests_oauth2client import BearerToken, TokenSerializer
@@ -1162,9 +1163,9 @@ token_serializer = TokenSerializer()
11621163bearer_token = BearerToken(" access_token" , expires_in = 60 ) # here is a sample token
11631164serialized_value = token_serializer.dumps(bearer_token)
11641165print (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
11701171deserialized_token = token_serializer.loads(serialized_value)
@@ -1229,9 +1230,9 @@ def custom_loader(serialized: bytes) -> dict[str, Any]:
12291230
12301231token_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 = " ..." )
12331234serialized = token_serializer.dumps(my_custom_token)
1234- assert serialized == b ' eyJhY2Nlc3NfdG9rZW4iOiAiLi4uIiwgInRva2VuX3R5cGUiOiAiQ3VzdG9tVG9rZW4ifQ=='
1235+ assert serialized == b " eyJhY2Nlc3NfdG9rZW4iOiAiLi4uIiwgInRva2VuX3R5cGUiOiAiQ3VzdG9tVG9rZW4ifQ=="
12351236assert token_serializer.loads(serialized) == my_custom_token
12361237```
12371238
0 commit comments