Skip to main content

A library for authenticating with GitHub across different operating systems

Project description

GitHub Authentication Library (githubauthlib)

A Python library for securely retrieving GitHub tokens from system keychains across different operating systems.

versions

PyPI version PyPI version Python

health

Quality Gate Status Coverage Security Rating Maintainability Rating Vulnerabilities Dependabot Status Code style: black

stats

Downloads License: MIT

Features

  • Cross-platform support:
    • macOS: Uses Keychain Access
    • Windows: Uses Credential Manager
    • Linux: Uses libsecret
  • Secure token retrieval with validation
  • Comprehensive exception hierarchy for precise error handling
  • Structured logging support
  • Token format validation (supports both personal and fine-grained tokens)
  • Robust credential parsing and sanitization

Prerequisites

All Platforms

  • Python 3.9 or higher
  • Git (with credentials configured)

Linux-Specific

# Ubuntu/Debian
sudo apt-get install libsecret-tools

# Fedora
sudo dnf install libsecret

Installation

From PyPI

pip install githubauthlib

From Source

# Clone the repository
git clone https://github.com/GIALaboratory/cloud-platform-engineering.git

# Navigate to the library directory
cd cloud-platform-engineering/githubauthlib

# Install the package
pip install .

Usage

from githubauthlib import (
    get_github_token,
    GitHubAuthError,
    TokenNotFoundError,
    InvalidTokenError,
    PlatformNotSupportedError,
    CredentialHelperError
)

try:
    token = get_github_token()
    print("Token retrieved successfully!")
    print(f"Token: {token[:10]}...")  # Show first 10 chars only
except TokenNotFoundError:
    print("No GitHub token found in system keychain")
except InvalidTokenError:
    print("Invalid token format detected")
except PlatformNotSupportedError:
    print("Current platform is not supported")
except CredentialHelperError:
    print("Failed to access system credential store")
except GitHubAuthError as e:
    print(f"GitHub authentication error: {e}")

Verifying Installation

# Check installed version
pip list | grep githubauthlib

# View package details
pip show githubauthlib

Development Setup

For development, you may want to add the package directory to your PYTHONPATH. See AUXILIARY.md for detailed instructions.

Breaking Changes in v2.0.0

⚠️ Important: Version 2.0.0 introduces breaking changes:

  • get_github_token() now raises specific exceptions instead of returning None
  • All error handling now uses structured logging instead of print statements
  • Token validation is now strict and validates format
  • Python 3.6, 3.7, and 3.8 support has been removed (EOL)

Migration Guide

Before (v1.x.x):

token = get_github_token()
if token:
    print("Success!")
else:
    print("Failed!")

After (v2.0.0):

try:
    token = get_github_token()
    print("Success!")
except TokenNotFoundError:
    print("No token found!")
except GitHubAuthError as e:
    print(f"Error: {e}")

Troubleshooting

  1. Token Not Found

    • Verify Git credentials are properly configured
    • Check system keychain for GitHub credentials
    • Handle TokenNotFoundError exception
  2. Permission Issues

    • Ensure proper system keychain access
    • Verify Python has required permissions
    • Handle CredentialHelperError exception
  3. Linux Issues

    • Confirm libsecret-tools is installed
    • Check D-Bus session is running
    • Handle PlatformNotSupportedError exception
  4. Invalid Token Format

    • Verify token starts with ghp_ or github_pat_
    • Handle InvalidTokenError exception

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

githubauthlib-2.0.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

githubauthlib-2.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: githubauthlib-2.0.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for githubauthlib-2.0.0.tar.gz
Algorithm Hash digest
SHA256 be15693e8d5f40cd9da2bca0bc5fb6aea28d578d34a9e044eac08b027eadcafc
MD5 a2108b6682d95a81be857d10517fc4f3
BLAKE2b-256 59496c0e28c3f4e2bb67370f1d28fe456d3426ddf6c8f151d2ea9ef55c214f5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for githubauthlib-2.0.0.tar.gz:

Publisher: workflow.yml on fleXRPL/githubauthlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: githubauthlib-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for githubauthlib-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d394c1540b5055032adff016afc0c274919b576c1d99638bffe151362e7e314f
MD5 ab44410d9bd39965dc7c0c708932e1f3
BLAKE2b-256 9fa0c6557d23f96cba58e587c4d1c1a9105ff1d3a99824338b3dab35f781e5c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for githubauthlib-2.0.0-py3-none-any.whl:

Publisher: workflow.yml on fleXRPL/githubauthlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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