Skip to content

Commit 2c796a0

Browse files
committed
fix: Add support for GitHub organization tokens (gho_)
- Add gho_ token validation in _validate_token function - Update documentation to mention organization token support - Add test case for organization token validation - Bump version to 2.0.1
1 parent 820f41e commit 2c796a0

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ A Python library for securely retrieving GitHub tokens from system keychains acr
3232
- Secure token retrieval with validation
3333
- Comprehensive exception hierarchy for precise error handling
3434
- Structured logging support
35-
- Token format validation (supports both personal and fine-grained tokens)
35+
- Token format validation (supports personal, organization, and fine-grained tokens)
3636
- Robust credential parsing and sanitization
3737

3838
## Prerequisites
@@ -166,7 +166,7 @@ except GitHubAuthError as e:
166166
- Handle `PlatformNotSupportedError` exception
167167

168168
4. **Invalid Token Format**
169-
- Verify token starts with `ghp_` or `github_pat_`
169+
- Verify token starts with `ghp_` (personal), `gho_` (organization), or `github_pat_` (fine-grained)
170170
- Handle `InvalidTokenError` exception
171171

172172
## Contributing

githubauthlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
get_github_token,
1515
)
1616

17-
__version__ = "2.0.0"
17+
__version__ = "2.0.1"
1818
__author__ = "garotm"
1919
__license__ = "MIT"
2020

githubauthlib/github_auth.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ def _validate_token(token: str) -> bool:
5858
return False
5959

6060
# GitHub personal access tokens start with 'ghp_' and are 40 characters long
61+
# GitHub organization tokens start with 'gho_' and are 40 characters long
6162
# GitHub fine-grained tokens start with 'github_pat_' and are longer
6263
# Allow for some flexibility in token length for testing
6364
if token.startswith("ghp_") and len(token) >= 40:
6465
return True
66+
elif token.startswith("gho_") and len(token) >= 40:
67+
return True
6568
elif token.startswith("github_pat_") and len(token) > 40:
6669
return True
6770

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="githubauthlib",
11-
version="2.0.0",
11+
version="2.0.1",
1212
description='A library for authenticating with GitHub across different operating systems',
1313
long_description=long_description,
1414
long_description_content_type='text/markdown',

tests/test_github_auth.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ def test_validate_token_fine_grained(self):
221221
)
222222
self.assertTrue(_validate_token(fine_grained_token))
223223

224+
def test_validate_token_organization(self):
225+
"""Test token validation with organization token."""
226+
from githubauthlib.github_auth import _validate_token
227+
228+
# Test organization token
229+
org_token = "gho_1234567890abcdef1234567890abcdef123456"
230+
self.assertTrue(_validate_token(org_token))
231+
224232
@patch("platform.system")
225233
@patch("subprocess.check_output")
226234
def test_linux_libsecret_empty_output(self, mock_subprocess, mock_platform):

0 commit comments

Comments
 (0)