@@ -257,29 +257,27 @@ is necessary but refreshing is done manually.
257
257
>>> client = OAuth2Session(client_id, token=token)
258
258
>>> r = client.get(protected_url)
259
259
260
- (Second) Define automatic token refresh automatic but update manually
260
+ (Second) Define automatic token refresh; no external update required.
261
261
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
262
262
263
- This is the, arguably awkward, middle between the basic and convenient refresh
264
- methods in which a token is automatically refreshed, but saving the new token
265
- is done manually.
263
+ Use this when the application does not need to take any action when the token
264
+ is updated. It requires no exception catching and results in clean code.
265
+ Remember however that you still need to update ``expires_in `` to trigger the
266
+ refresh. And be sure to save ``client.token `` before destroying ``client ``.
266
267
267
268
.. code-block :: pycon
268
269
269
- >>> from requests_oauthlib import OAuth2Session, TokenUpdated
270
- >>> try:
271
- ... client = OAuth2Session(client_id, token=token,
272
- ... auto_refresh_kwargs=extra, auto_refresh_url=refresh_url)
273
- ... r = client.get(protected_url)
274
- >>> except TokenUpdated as e:
275
- ... token_saver(e.token)
270
+ >>> from requests_oauthlib import OAuth2Session
271
+ >>> client = OAuth2Session(client_id, token=token,
272
+ ... auto_refresh_kwargs=extra, auto_refresh_url=refresh_url)
273
+ >>> r = client.get(protected_url)
276
274
277
- (Third, Recommended ) Define automatic token refresh and update
278
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
275
+ (Third) Define automatic token refresh with external update
276
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
279
277
280
- The third and recommended method will automatically fetch refresh tokens and
281
- save them. It requires no exception catching and results in clean code. Remember
282
- however that you still need to update `` expires_in `` to trigger the refresh .
278
+ The third method is the same as the second, only with a custom token update
279
+ handler. Use this if your application needs to react immediately to a change in
280
+ access token .
283
281
284
282
.. code-block :: pycon
285
283
0 commit comments