Token Manager¶
Token Manager classes.
There should be a 1-to-1 mapping betwen an instance of a subclass of
BaseTokenManager and a Reddit instance.
A few trivial token manager classes are provided here, but it is expected that PRAW users will create their own token manager classes suitable for their needs.
See ref:using_refresh_tokens for examples on how to leverage these classes.
-
class
praw.util.token_manager.BaseTokenManager¶ An abstract class for all token managers.
-
__init__()¶ Prepare attributes needed by all token manager classes.
-
post_refresh_callback(authorizer)¶ Handle callback that is invoked after a refresh token is used.
- Parameters
authorizer – The
prawcore.Authorizerinstance used containingaccess_tokenandrefresh_tokenattributes.
This function will be called after refreshing the access and refresh tokens. This callback can be used for saving the updated
refresh_token.
-
pre_refresh_callback(authorizer)¶ Handle callback that is invoked before refreshing PRAW’s authorization.
- Parameters
authorizer – The
prawcore.Authorizerinstance used containingaccess_tokenandrefresh_tokenattributes.
This callback can be used to inspect and modify the attributes of the
prawcore.Authorizerinstance, such as setting therefresh_token.
-
-
class
praw.util.token_manager.FileTokenManager(filename)¶ Provides a trivial single-file based token manager.
-
__init__(filename)¶ Load and save refresh tokens from a file.
- Parameters
filename – The file the contains the refresh token.
-
post_refresh_callback(authorizer)¶ Update the saved copy of the refresh token.
-
pre_refresh_callback(authorizer)¶ Load the refresh token from the file.
-