Skip to main content

Authenticate against OAuth2 Provider in Python CLIs

Project description

oauth2-cli-auth

LICENSE CircleCI GitHub Release PyPI version codecov Quality Gate Status Code Smells Maintainability Rating Security Rating Renovate pre-commit


Authenticate against OAuth2 Provider in Python CLIs

Features

  • Simple
  • Fancy callback page

Requirements

  • Python 3.9+

Installation

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:

from oauth2_cli_auth import get_access_token_with_browser_open, OAuth2ClientInfo

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

from oauth2_cli_auth import get_access_token_with_browser_open, OAuth2ClientInfo

client_info = OAuth2ClientInfo(
    client_id="<clientId>",
    authorization_url="<authorizeUrl>",
    token_url="<TokenUrl>",
    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

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 maintainer

To get started please read the Contribution Guidelines.

Development

Requirements

Test

poetry run pytest .

Build

poetry install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oauth2_cli_auth-1.5.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

oauth2_cli_auth-1.5.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file oauth2_cli_auth-1.5.0.tar.gz.

File metadata

  • Download URL: oauth2_cli_auth-1.5.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/5.15.0-1057-aws

File hashes

Hashes for oauth2_cli_auth-1.5.0.tar.gz
Algorithm Hash digest
SHA256 2621c67290d57dcbcd99cbce45e5c82b669f942749e1c54306cbdeef2fe4a3d3
MD5 bef716238bc947818d8abec3f8ee1c1c
BLAKE2b-256 776e99b32485f3cf5722395e5d648cc46d2d8c609b08df6f1a496f048e39319f

See more details on using hashes here.

File details

Details for the file oauth2_cli_auth-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: oauth2_cli_auth-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/5.15.0-1057-aws

File hashes

Hashes for oauth2_cli_auth-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60d017fe682c8ab0a9b9e79312ec51a7faf0082e160c8660ae91a8b85696ad16
MD5 0be6419cd06fa18eb1c1391f8e71686f
BLAKE2b-256 fce9bfb85d3f7fb312c412e067e8321d88dcb10e166bb4bbd0a8de7a23a74dc1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page