33A Python library for securely retrieving GitHub tokens from system keychains across different operating systems.
44
55#### versions
6+
67[ ![ PyPI version] ( https://badge.fury.io/py/githubauthlib.svg )] ( https://pypi.org/project/githubauthlib/ )
78[ ![ PyPI version] ( https://img.shields.io/pypi/v/githubauthlib.svg )] ( https://pypi.org/project/githubauthlib/ )
89[ ![ Python] ( https://img.shields.io/pypi/pyversions/githubauthlib.svg )] ( https://pypi.org/project/githubauthlib/ )
910
1011#### health
12+
1113[ ![ Quality Gate Status] ( https://sonarcloud.io/api/project_badges/measure?project=fleXRPL_githubauthlib&metric=alert_status )] ( https://sonarcloud.io/summary/new_code?id=fleXRPL_githubauthlib )
1214[ ![ Coverage] ( https://sonarcloud.io/api/project_badges/measure?project=fleXRPL_githubauthlib&metric=coverage )] ( https://sonarcloud.io/summary/new_code?id=fleXRPL_githubauthlib )
1315[ ![ Security Rating] ( https://sonarcloud.io/api/project_badges/measure?project=fleXRPL_githubauthlib&metric=security_rating )] ( https://sonarcloud.io/summary/new_code?id=fleXRPL_githubauthlib )
@@ -21,23 +23,23 @@ A Python library for securely retrieving GitHub tokens from system keychains acr
2123[ ![ Downloads] ( https://pepy.tech/badge/githubauthlib )] ( https://pepy.tech/project/githubauthlib )
2224[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
2325
24-
2526## Features
2627
2728- Cross-platform support:
2829 - macOS: Uses Keychain Access
2930 - Windows: Uses Credential Manager
3031 - Linux: Uses libsecret
31- - Secure token retrieval
32- - Token validation
33- - Comprehensive error handling
34- - Logging support
32+ - Secure token retrieval with validation
33+ - Comprehensive exception hierarchy for precise error handling
34+ - Structured logging support
35+ - Token format validation (supports both personal and fine-grained tokens)
36+ - Robust credential parsing and sanitization
3537
3638## Prerequisites
3739
3840### All Platforms
3941
40- - Python 3.6 or higher
42+ - Python 3.9 or higher
4143- Git (with credentials configured)
4244
4345### Linux-Specific
@@ -74,16 +76,29 @@ pip install .
7476## Usage
7577
7678``` python
77- from githubauthlib import get_github_token, GitHubAuthError
79+ from githubauthlib import (
80+ get_github_token,
81+ GitHubAuthError,
82+ TokenNotFoundError,
83+ InvalidTokenError,
84+ PlatformNotSupportedError,
85+ CredentialHelperError
86+ )
7887
7988try :
8089 token = get_github_token()
81- if token:
82- print (" Token retrieved successfully!" )
83- else :
84- print (" No token found in system keychain" )
90+ print (" Token retrieved successfully!" )
91+ print (f " Token: { token[:10 ]} ... " ) # Show first 10 chars only
92+ except TokenNotFoundError:
93+ print (" No GitHub token found in system keychain" )
94+ except InvalidTokenError:
95+ print (" Invalid token format detected" )
96+ except PlatformNotSupportedError:
97+ print (" Current platform is not supported" )
98+ except CredentialHelperError:
99+ print (" Failed to access system credential store" )
85100except GitHubAuthError as e:
86- print (f " Error retrieving token : { e} " )
101+ print (f " GitHub authentication error : { e} " )
87102```
88103
89104## Verifying Installation
@@ -100,19 +115,59 @@ pip show githubauthlib
100115
101116For development, you may want to add the package directory to your PYTHONPATH. See [ AUXILIARY.md] ( AUXILIARY.md ) for detailed instructions.
102117
118+ ## Breaking Changes in v2.0.0
119+
120+ ⚠️ ** Important** : Version 2.0.0 introduces breaking changes:
121+
122+ - ` get_github_token() ` now raises specific exceptions instead of returning ` None `
123+ - All error handling now uses structured logging instead of print statements
124+ - Token validation is now strict and validates format
125+ - Python 3.6, 3.7, and 3.8 support has been removed (EOL)
126+
127+ ### Migration Guide
128+
129+ ** Before (v1.x.x):**
130+
131+ ``` python
132+ token = get_github_token()
133+ if token:
134+ print (" Success!" )
135+ else :
136+ print (" Failed!" )
137+ ```
138+
139+ ** After (v2.0.0):**
140+
141+ ``` python
142+ try :
143+ token = get_github_token()
144+ print (" Success!" )
145+ except TokenNotFoundError:
146+ print (" No token found!" )
147+ except GitHubAuthError as e:
148+ print (f " Error: { e} " )
149+ ```
150+
103151## Troubleshooting
104152
1051531 . ** Token Not Found**
106154 - Verify Git credentials are properly configured
107155 - Check system keychain for GitHub credentials
156+ - Handle ` TokenNotFoundError ` exception
108157
1091582 . ** Permission Issues**
110159 - Ensure proper system keychain access
111160 - Verify Python has required permissions
161+ - Handle ` CredentialHelperError ` exception
112162
1131633 . ** Linux Issues**
114164 - Confirm libsecret-tools is installed
115165 - Check D-Bus session is running
166+ - Handle ` PlatformNotSupportedError ` exception
167+
168+ 4 . ** Invalid Token Format**
169+ - Verify token starts with ` ghp_ ` or ` github_pat_ `
170+ - Handle ` InvalidTokenError ` exception
116171
117172## Contributing
118173
@@ -124,4 +179,4 @@ For development, you may want to add the package directory to your PYTHONPATH. S
124179
125180## License
126181
127- This project is licensed under the MIT License - see the LICENSE file for details.
182+ This project is licensed under the MIT License - see the [ LICENSE] ( LICENSE ) file for details.
0 commit comments