https://github.com/timo-reymann/python-oauth2-cli-auth
Authenticate against OAuth2 Provider in Python CLIs
https://github.com/timo-reymann/python-oauth2-cli-auth
cli oauth2 pip python
Last synced: about 1 month ago
JSON representation
Authenticate against OAuth2 Provider in Python CLIs
- Host: GitHub
- URL: https://github.com/timo-reymann/python-oauth2-cli-auth
- Owner: timo-reymann
- License: mit
- Created: 2023-12-09T12:14:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-29T14:24:12.000Z (7 months ago)
- Last Synced: 2024-10-29T17:33:47.717Z (7 months ago)
- Topics: cli, oauth2, pip, python
- Language: Python
- Homepage: https://pypi.org/project/oauth2-cli-auth/
- Size: 378 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
oauth2-cli-auth
===
[](https://github.com/timo-reymann/python-oauth2-cli-auth/blob/main/LICENSE)
[](https://app.circleci.com/pipelines/github/timo-reymann/python-oauth2-cli-auth)
[](https://github.com/timo-reymann/python-oauth2-cli-auth/releases)
[](https://pypi.org/project/oauth2-cli-auth)

[](https://codecov.io/gh/timo-reymann/python-oauth2-cli-auth)
[](https://sonarcloud.io/summary/new_code?id=timo-reymann_python-oauth2-cli-auth)
[](https://sonarcloud.io/summary/new_code?id=timo-reymann_python-oauth2-cli-auth)
[](https://sonarcloud.io/summary/new_code?id=timo-reymann_python-oauth2-cli-auth)
[](https://sonarcloud.io/summary/new_code?id=timo-reymann_python-oauth2-cli-auth)
[](https://renovatebot.com)
[](https://pre-commit.com/)
![]()
Authenticate against OAuth2 Provider in Python CLIs## Features
- Simple
- Fancy callback page## Requirements
- Python 3.9+
## Installation
```sh
pip install oauth2-cli-auth
```## Usage
### Simple with OIDC well known configuration endpoint
This should work for every provider supporting OIDC e.g. `gitlab.com`:
```python
from oauth2_cli_auth import get_access_token_with_browser_open, OAuth2ClientInfoclient_info = OAuth2ClientInfo.from_oidc_endpoint(
"https://gitlab.com/.well-known/openid-configuration",
client_id="my-client-id",
scopes=["openid"]
)try:
token = get_access_token_with_browser_open(client_info)
print(f"Obtained token '{token}'")
except ValueError:
print("Failed to obtain token")
```### Simple with manual endpoint specification
The following should work for almost all use cases, for rest please check the lib docs.
```python
from oauth2_cli_auth import get_access_token_with_browser_open, OAuth2ClientInfoclient_info = OAuth2ClientInfo(
client_id="",
authorization_url="",
token_url="",
scopes=["scopeA", "scopeB"]
)try:
token = get_access_token_with_browser_open(client_info)
print(f"Obtained token '{token}'")
except ValueError:
print("Failed to obtain token")
```## Motivation
Building oauth2 integration for Python apps come quite handy, especially with Gitlab integration etc.
It is a bit cumbersome to do it manually everytime, existing solutions are way to overkill to put on this problem.
So I created this small library without any dependencies besides the python standard library.## Documentation
- [Library documentation](https://timo-reymann.github.io/python-oauth2-cli-auth)
## Contributing
I love your input! I want to make contributing to this project as easy and transparent as possible, whether it's:
- Reporting a bug
- Discussing the current state of the configuration
- Submitting a fix
- Proposing new features
- Becoming a maintainerTo get started please read the [Contribution Guidelines](./CONTRIBUTING.md).
## Development
### Requirements
- Python 3.9+
- [pre-commit](https://pre-commit.com/)
- Poetry### Test
```
poetry run pytest .
```### Build
```sh
poetry install
```