AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Revert "fix(backend): Fix Google OAuth token revocation" (#10493)
Reinier van der Leer9ca75d93f775
diff --git a/autogpt_platform/backend/backend/integrations/oauth/google.py b/autogpt_platform/backend/backend/integrations/oauth/google.pyindex aced8d3385..bba2bc71c5 100644--- a/autogpt_platform/backend/backend/integrations/oauth/google.py+++ b/autogpt_platform/backend/backend/integrations/oauth/google.py@@ -1,12 +1,11 @@import logging-from datetime import datetimefrom typing import Optionalfrom google.auth.external_account_authorized_user import (- Credentials as GoogleExternalAccountCredentials,+ Credentials as ExternalAccountCredentials,)from google.auth.transport.requests import AuthorizedSession, Request-from google.oauth2.credentials import Credentials as GoogleOAuth2Credentials+from google.oauth2.credentials import Credentialsfrom google_auth_oauthlib.flow import Flowfrom pydantic import SecretStr@@ -95,7 +94,9 @@ class GoogleOAuthHandler(BaseOAuthHandler):username=username,access_token=SecretStr(google_creds.token),refresh_token=(SecretStr(google_creds.refresh_token)),- access_token_expires_at=int(google_creds.expiry.timestamp()),+ access_token_expires_at=(+ int(google_creds.expiry.timestamp()) if google_creds.expiry else None+ ),refresh_token_expires_at=None,scopes=granted_scopes,)@@ -106,7 +107,7 @@ class GoogleOAuthHandler(BaseOAuthHandler):return credentialsasync def revoke_tokens(self, credentials: OAuth2Credentials) -> bool:- session = AuthorizedSession(self._to_google_credentials(credentials))+ session = AuthorizedSession(credentials)session.post(self.revoke_uri,params={"token": credentials.access_token.get_secret_value()},@@ -115,7 +116,7 @@ class GoogleOAuthHandler(BaseOAuthHandler):return Truedef _request_email(- self, creds: GoogleOAuth2Credentials | GoogleExternalAccountCredentials+ self, creds: Credentials | ExternalAccountCredentials) -> str | None:session = AuthorizedSession(creds)response = session.get(self.EMAIL_ENDPOINT)@@ -129,8 +130,17 @@ class GoogleOAuthHandler(BaseOAuthHandler):async def _refresh_tokens(self, credentials: OAuth2Credentials) -> OAuth2Credentials:- google_creds = self._to_google_credentials(credentials)+ # Google credentials should ALWAYS have a refresh token+ assert credentials.refresh_token+ google_creds = Credentials(+ token=credentials.access_token.get_secret_value(),+ refresh_token=credentials.refresh_token.get_secret_value(),+ token_uri=self.token_uri,+ client_id=self.client_id,+ client_secret=self.client_secret,+ scopes=credentials.scopes,+ )# Google's OAuth library is poorly typed so we need some of these:assert google_creds.refresh_tokenassert google_creds.scopes@@ -162,24 +172,3 @@ class GoogleOAuthHandler(BaseOAuthHandler):},scopes=scopes,)-- def _to_google_credentials(- self, credentials: OAuth2Credentials- ) -> GoogleOAuth2Credentials:- """- Converts our `OAuth2Credentials` to `google.oauth2.credentials.Credentials`- for use with Google APIs.- """- # Google credentials should ALWAYS have a refresh token and expiry timestamp- assert credentials.refresh_token- assert credentials.access_token_expires_at-- return GoogleOAuth2Credentials(- token=credentials.access_token.get_secret_value(),- refresh_token=credentials.refresh_token.get_secret_value(),- token_uri=self.token_uri,- client_id=self.client_id,- client_secret=self.client_secret,- scopes=credentials.scopes,- expiry=datetime.fromtimestamp(credentials.access_token_expires_at),- )