diff --git a/README.md b/README.md index b999e2c..bb1b83f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/githubauthlib/__init__.py b/githubauthlib/__init__.py index 04b1b36..a930d3f 100644 --- a/githubauthlib/__init__.py +++ b/githubauthlib/__init__.py @@ -14,7 +14,7 @@ get_github_token, ) -__version__ = "2.0.0" +__version__ = "2.0.1" __author__ = "garotm" __license__ = "MIT" diff --git a/githubauthlib/github_auth.py b/githubauthlib/github_auth.py index 6c99d65..23eee7d 100644 --- a/githubauthlib/github_auth.py +++ b/githubauthlib/github_auth.py @@ -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 diff --git a/setup.py b/setup.py index 2bd067e..04178b9 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/tests/test_github_auth.py b/tests/test_github_auth.py index c533bf9..c24417d 100644 --- a/tests/test_github_auth.py +++ b/tests/test_github_auth.py @@ -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):