Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.
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
31 changes: 31 additions & 0 deletions gsoc/management/commands/googleapiauth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from google_auth_oauthlib.flow import InstalledAppFlow
import os.path

from google.auth.transport.requests import Request

from django.core.management import BaseCommand

from gsoc.settings import GOOGLE_API_SCOPES, GOOGLE_API_CLIENT_CONFIG


class Command(BaseCommand):
help = 'Generates the api token pickle for authenticating Google API.'
requires_system_checks = False # for debugging

def handle(self, *args, **options):
creds = None
if os.path.exists('gcal_api_token.pickle'):
with open('gcal_api_token.pickle', 'rb') as token:
creds = pickle.load(token)

if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.Refresh(Request())
else:
flow = InstalledAppFlow.from_client_config(
GOOGLE_API_CLIENT_CONFIG, GOOGLE_API_SCOPES
)
creds = flow.run_console()

with open('gcal_api_token.pickle', 'wb') as token:
pickle.dump(creds, token)
31 changes: 0 additions & 31 deletions scripts/gengcaltokenpickle.py

This file was deleted.

16 changes: 16 additions & 0 deletions settings_local.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ REPLY_EMAIL = 'gsoc-admins@python.org'
RECAPTCHA_PRIVATE_KEY = '6LdAVqIUAAAAACv_tNPudwx_pD9dbjtwvr3WwQ9Y'
RECAPTCHA_PUBLIC_KEY = '6LdAVqIUAAAAAAt6baSHpGXr1LvJ0n1aCl_oqukj'
RECAPTCHA_THRESHOLD = 0.1

# google oauth client_config
GOOGLE_API_SCOPES = [
'https://www.googleapis.com/auth/calendar.events',
]
GOOGLE_API_CLIENT_CONFIG = {
"installed": {
"client_id": "",
"project_id": "",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "p62APV3jXWciaWRzk9D9YAMm",
"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]
}
}