Metadata-Version: 2.1
Name: cli-oauth2
Version: 0.1.0
Summary: Helper library for OAuth2 in command-line tools
Author-email: Ilya Zverev <ilya@zverev.info>
Project-URL: Homepage, https://github.com/Zverik/cli-oauth2
Project-URL: Bug Tracker, https://github.com/Zverik/cli-oauth2/issues
Classifier: Programming Language :: Python :: 3
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE

# CLI OAuth2

This Python library help command-line tool authors to use
OAuth2 services. Built using [requests-oauthlib](https://requests-oauthlib.readthedocs.io/)
with parts of [google\_auth\_oauthlib](https://github.com/googleapis/google-auth-library-python-oauthlib).

## Usage

Do something like this:

```python
from oauthcli.providers import OpenStreetMapDevAuth

auth = OpenStreetMapAuth(client_id, secret_id).auth_server()
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 uses `urn:ietf:wg:oauth:2.0:oob` redirect uri.
* `authorized` returns whether there is an active access token.
* `get`, `post` etc call the relevant `requests` methods, but often shadow
  the server name. See the example above.
* `session` is the underlying [OAuth2Session](https://requests-oauthlib.readthedocs.io/en/latest/api.html#oauth-2-0-session) object.

There are some predefined providers:

* `OpenStreetMapAuth`
* `OpenStreetMapDevAuth`
* `GoogleAuth`
* `GitHubAuth`
* `MastodonAuth` (requires a `server` parameter)
* `RedditAuth`
* `FacebookAuth`
* `LinkedInAuth`

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`.

## Author and License

Written by Ilya Zverev, published under Apache License 2.0.

Contains portions of [google\_auth\_oauthlib](https://github.com/googleapis/google-auth-library-python-oauthlib)
as of commit 1a9dca889357b93bdad17d75a28ac81e3ba6067f, published under
Apache License 2.0.
