diff --git a/src/secops/auth.py b/src/secops/auth.py index 2d34954..c7492c7 100644 --- a/src/secops/auth.py +++ b/src/secops/auth.py @@ -188,7 +188,11 @@ def _get_credentials( """Get credentials from various sources.""" try: if credentials: - google_credentials = credentials.with_scopes(self.scopes) + if hasattr(credentials, "with_scopes"): + google_credentials = credentials.with_scopes(self.scopes) + else: + # Assume credentials are already scoped + google_credentials = credentials elif service_account_info: google_credentials = ( diff --git a/tests/test_auth.py b/tests/test_auth.py index a6d6fe2..4164bdb 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -73,3 +73,16 @@ def test_custom_user_agent(): assert session is not None assert hasattr(session, "headers") assert session.headers.get("User-Agent") == "secops-wrapper-sdk" + + +def test_bearer_token_credentials_accepted(): + """Test scope passed for token credentials""" + from google.oauth2.credentials import Credentials as OAuthCredentials + + creds = OAuthCredentials(token="fake-bearer-token") + assert not hasattr(creds, "with_scopes"), ( + "Test assumption broken: OAuthCredentials now has with_scopes" + ) + + auth = SecOpsAuth(credentials=creds) + assert auth.credentials is creds \ No newline at end of file