Skip to content

Replace oauth2client with google-auth and google-auth-oauthlib in google-calendar integration #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
10 changes: 10 additions & 0 deletions .github/workflows/zulip-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,22 @@ jobs:
ref: ${{ matrix.server_version }}
path: server

- name: Upgrade pip
run: |
python -m pip install --upgrade pip

- name: Install dependencies
run: |
cd server
# This is the main setup job for the test suite
./tools/ci/setup-backend --skip-dev-db-build

# Install PGroonga extension
sudo sh -c 'echo "deb http://packages.groonga.org/debian/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/groonga.list'
sudo apt-get update
sudo apt-get install -y postgresql-14-pgroonga
sudo service postgresql restart

# Cleaning caches is mostly unnecessary in GitHub Actions, because
# most builds don't get to write to the cache.
# scripts/lib/clean_unused_caches.py --verbose --threshold 0
Expand Down
25 changes: 16 additions & 9 deletions zulip/integrations/google/google-calendar
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import time
from typing import List, Optional, Set, Tuple

import dateutil.parser
import httplib2
import pytz
from oauth2client import client
from oauth2client.file import Storage
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow

try:
from googleapiclient import discovery
Expand Down Expand Up @@ -88,7 +87,7 @@ if not options.zulip_email:
zulip_client = zulip.init_from_options(options)


def get_credentials() -> client.Credentials:
def get_credentials() -> Credentials:
"""Gets valid user credentials from storage.

If nothing has been stored, or if the stored credentials are invalid,
Expand All @@ -101,9 +100,18 @@ def get_credentials() -> client.Credentials:
try:
credential_path = os.path.join(HOME_DIR, "google-credentials.json")

store = Storage(credential_path)
return store.get()
except client.Error:
if os.path.exists(credential_path):
# Load credentials from the file
credentials = Credentials.from_authorized_user_file(credential_path, SCOPES)
else:
# Run the OAuth flow to get new credentials
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES)
credentials = flow.run_local_server(port=0)
# Save the credentials for the next run
with open(credential_path, "w") as token:
token.write(credentials.to_json())
return credentials
except FileNotFoundError:
logging.exception("Error while trying to open the `google-credentials.json` file.")
sys.exit(1)
except OSError:
Expand All @@ -113,8 +121,7 @@ def get_credentials() -> client.Credentials:

def populate_events() -> Optional[None]:
credentials = get_credentials()
creds = credentials.authorize(httplib2.Http())
service = discovery.build("calendar", "v3", http=creds)
service = discovery.build("calendar", "v3", credentials=credentials)

now = datetime.datetime.now(pytz.utc).isoformat()
feed = (
Expand Down
7 changes: 5 additions & 2 deletions zulip/integrations/google/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
httplib2>=0.22.0
oauth2client>=4.1.3
google-auth>=2.0.0
google-auth-oauthlib>=0.4.6
google-api-python-client>=2.0.0
types-google-auth==2.0.0
types-google-auth-oauthlib==0.4.6
2 changes: 1 addition & 1 deletion zulip_bots/zulip_bots/bots/google_search/google_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def google_search(keywords: str) -> List[Dict[str, str]]:
# Gets all search URLs
search = soup.find(id="search")
assert isinstance(search, Tag)
anchors = search.findAll("a")
anchors = search.find_all("a")
results = []

for a in anchors:
Expand Down
2 changes: 1 addition & 1 deletion zulip_bots/zulip_bots/bots/twitpost/twitpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def usage(self) -> str:

def initialize(self, bot_handler: AbstractBotHandler) -> None:
self.config_info = bot_handler.get_config_info("twitter")
auth = tweepy.OAuthHandler(
auth = tweepy.OAuth1UserHandler(
self.config_info["consumer_key"], self.config_info["consumer_secret"]
)
auth.set_access_token(
Expand Down
Loading