API for managing stored OAuth credentials.
Project description
Python Library for storing OAuth credentials in many locations
What's this for?
By their very nature, OAuth credentials are valuable and dangerous, and have to be stored securely. As a result, the same tasks to store these tokens in a simple and secure fashion have to be written each time, or copied and pasted around - leading to potential issues as problems are found and not fixed in all places.
This library will store OAuth tokens in any of the following places:
- Secret Manager
- Firestore
- Google Cloud Storage files
- A local
json
file
Other storage locations can be added at will simply by forking this library and extending the appropriate abstract classes.
Initial Setup And Installation
Examples
Fetching a token from storage
from auth.credentials_helpers import encode_key
from auth.secret_manager import SecretManager
manager = SecretManager(project='<gcp project name>')
key = manager.get_document(encode_key('<token id>'))
Note the use of encode_key
. This is because many of the storage systems
supported do not allow special characters, and the most convenient identifier
for most OAuth tokens is the email address of the user. encode_key
is a
base64 encoder - and no decoding is necessary.
The example given uses Secret Manager (part of Google Cloud). To use (say) GCS, the code would change like this:
from auth.credentials_helpers import encode_key
from auth.gcs_datastore import GCSDatastore
manager = GCSDatastore(project='<gcp project name>', bucket='<gcs bucket>')
key = manager.get_document(encode_key('<token id>'))
All that changes is where the datastore is!
Storing a token in Secret Manager
from auth.secret_manager import SecretManager
manager = SecretManager(project='<gcp project name>')
manager.update_document(id=encode_key('<token_id>'), new_data=<token string>)
This will implicitly create a secret
if there was not one already, or simply
update an existing secret with a new 'live' version of the secret.
Listing all the available secrets
from auth.secret_manager import SecretManager
manager = SecretManager(project='<gcp project name>')
manager.list_documents()
Removing a secret
from auth.secret_manager import SecretManager
manager = SecretManager(project='<gcp project name>')
manager.delete_document(id=encode_key('<token_id>'))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python_oauth_token_manager-0.5.3.tar.gz
.
File metadata
- Download URL: python_oauth_token_manager-0.5.3.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dea4d65db4e150d2767e8c876c60a06f4262f066d755a0f7fb28fa9ad6249f7 |
|
MD5 | 5362b1167330ef38be6a5a21e41d632b |
|
BLAKE2b-256 | d211509c7e3d82fbac770e61b69c482535298c59cabdad29d7d2ed2dc0bec302 |
File details
Details for the file python_oauth_token_manager-0.5.3-py3-none-any.whl
.
File metadata
- Download URL: python_oauth_token_manager-0.5.3-py3-none-any.whl
- Upload date:
- Size: 29.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc0d912299d438dd71b94a0ae8128d8fd08126417b6d76d5a6af1600dbf3a396 |
|
MD5 | c0883ecfecf2fba71882bc1e7c6c972a |
|
BLAKE2b-256 | f16c3009b2e31046d96b27e0b50af48d6433a8b744a8fbe86a3540a0f7561d2f |