CLI OAuth2
This Python library help command-line tool authors to use OAuth2 services. Built using requests-oauthlib with parts of google_auth_oauthlib.
Installation
pip install cli-oauth2
Usage
Do something like this:
from oauthcli import OpenStreetMapAuth
auth = OpenStreetMapAuth(
client_id, secret_id, ['read_prefs']
).auth_server(token_test=lambda r: r.get('user/details'))
data = auth.get('user/details.json')
if data.status_code != 200:
print(f'Error {data.status_code}: {data.text})')
else:
print(f'Hello, {data.json()["user"]["display_name"]}')
Tokens are saved to disk, so subsequent runs won't require authorization.
Auth objects have these methods and properties:
auth_server()opens a web browser and catches the response by starting a local server.auth_code()opens a web browser and expected a user to copy the code presented by the provider. It usesurn:ietf:wg:oauth:2.0:oobredirect uri.authorizedreturns whether there is an active access token.get,postetc call the relevantrequestsmethods, but often shadow the server name. See the example above.sessionis the underlying OAuth2Session object.
There are some predefined providers:
OpenStreetMapAuthOpenStreetMapDevAuthGoogleAuthGitHubAuthMastodonAuth(requires aserverparameter)RedditAuthFacebookAuthLinkedInAuth
Note that only OSM and GitHub providers were tested. I welcome pull requests with fixes.
If you need to use another provider, just subclass AuthFlow and
pass it provider_id (the key for the stored token map),
OAuth2Session(client_id, scope=scopes),
auth_url, token_url, and client_secret.
Cleanup
The tool stores tokens in a json in the configuration directory.
To clean some or all tokens, use the oauthclean command-line tool.
Author and License
Written by Ilya Zverev, published under Apache License 2.0.
Contains portions of google_auth_oauthlib as of commit 1a9dca889357b93bdad17d75a28ac81e3ba6067f, published under Apache License 2.0.
Metadata
Release files for cli-oauth2 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cli-oauth2-0.3.1.tar.gz | 12.1 kB | Without provenance | Details for cli-oauth2-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cli_oauth2-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for cli_oauth2-0.3.1-py3-none-any.whl |
Total release size: 27.9 kB
Release files / cli-oauth2-0.3.1.tar.gz
| Download URL | cli-oauth2-0.3.1.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f989848989f6778c296e6c91ff6efada429f9cf647b8432a1b40e067670fc5e
|
|
BLAKE2b-256 checksum How to use checksums |
cb472b9fd0bb9285249914ca87c231853212e43d550654a0d1b4aa519f836261
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.10.8
|
Release files / cli_oauth2-0.3.1-py3-none-any.whl
| Download URL | cli_oauth2-0.3.1-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b18f69770673892d2202b408d04246ea23a5e5d05cfca1577d8c1fb162dcb1c5
|
|
BLAKE2b-256 checksum How to use checksums |
a66cee8728c95e28ea4103b625975b34e961b639fe95a985d5da1efe2d08c342
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.10.8
|
Security for cli-oauth2 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.