Skip to main content

oauth2-cli-auth

LICENSE CircleCI GitHub Release PyPI version PyPI - Downloads 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

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-2.0.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oauth2_cli_auth-2.0.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: oauth2_cli_auth-2.0.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.8.0-1029-aws

File hashes

Hashes for oauth2_cli_auth-2.0.0.tar.gz
Algorithm Hash digest
SHA256 b28d089fb7323875579fef9d96334d2f59e32c5c06a3251e858779c2e18f442e
MD5 95214e0650c3df58b5365ab02d9886a6
BLAKE2b-256 72eaae3c7e7d9ea244d181e0044b911f76d6df997cd28e3723ea55d00f723df7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oauth2_cli_auth-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.11 Linux/6.8.0-1029-aws

File hashes

Hashes for oauth2_cli_auth-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 086bcc9a88aa03c3bc2dc9ffc98c02b6b623dbf613e82e2dc93712c6a16e1e12
MD5 c79eee446dc18e6d17ad80adb8273580
BLAKE2b-256 67b2bc8cf6f368e4a1b8fe7550532d834df48b3ef39c4fc7b9b831a0e8e5c631

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page