Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ A Python library for securely retrieving GitHub tokens from system keychains acr
- 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)
- Token format validation (supports personal, organization, and fine-grained tokens)
- Robust credential parsing and sanitization

## Prerequisites
Expand Down Expand Up @@ -166,7 +166,7 @@ except GitHubAuthError as e:
- Handle `PlatformNotSupportedError` exception

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

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion githubauthlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
get_github_token,
)

__version__ = "2.0.0"
__version__ = "2.0.1"
__author__ = "garotm"
__license__ = "MIT"

Expand Down
3 changes: 2 additions & 1 deletion githubauthlib/github_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def _validate_token(token: str) -> bool:
return False

# GitHub personal access tokens start with 'ghp_' and are 40 characters long
# GitHub organization tokens start with 'gho_' and are 40 characters long
# GitHub fine-grained tokens start with 'github_pat_' and are longer
# Allow for some flexibility in token length for testing
if token.startswith("ghp_") and len(token) >= 40:
if (token.startswith("ghp_") or token.startswith("gho_")) and len(token) >= 40:
return True
elif token.startswith("github_pat_") and len(token) > 40:
return True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="githubauthlib",
version="2.0.0",
version="2.0.1",
description='A library for authenticating with GitHub across different operating systems',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
8 changes: 8 additions & 0 deletions tests/test_github_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ def test_validate_token_fine_grained(self):
)
self.assertTrue(_validate_token(fine_grained_token))

def test_validate_token_organization(self):
"""Test token validation with organization token."""
from githubauthlib.github_auth import _validate_token

# Test organization token
org_token = "gho_1234567890abcdef1234567890abcdef123456"
self.assertTrue(_validate_token(org_token))

@patch("platform.system")
@patch("subprocess.check_output")
def test_linux_libsecret_empty_output(self, mock_subprocess, mock_platform):
Expand Down