From b502302a24217678c5d54cb5c2caeac24ca59eed Mon Sep 17 00:00:00 2001 From: Amos Boldor Date: Fri, 17 Feb 2017 10:44:32 -0800 Subject: [PATCH] change some code for oauth2.0 FLOW --- neuropy/neuropy/client_secret.json | 15 --------------- neuropy/neuropy/oauth.py | 14 ++++++-------- neuropy/todo/views.py | 13 ++++++------- neuropy/userprofile/views.py | 15 +++++++-------- 4 files changed, 19 insertions(+), 38 deletions(-) delete mode 100644 neuropy/neuropy/client_secret.json diff --git a/neuropy/neuropy/client_secret.json b/neuropy/neuropy/client_secret.json deleted file mode 100644 index 957f99b..0000000 --- a/neuropy/neuropy/client_secret.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "web":{ - "client_id":"662194819445-oc6c5e7uk8025mffbv035g876l6amk5q.apps.googleusercontent.com", - "project_id":"homemon-go-1478832356580", - "auth_uri":"https://accounts.google.com/o/oauth2/auth", - "token_uri":"https://accounts.google.com/o/oauth2/token", - "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs", - "client_secret":"ArEd-PCRqt1JmxzFtWzepNzl", - "redirect_uris":[ - "http://localhost:8000/oauth2callback", - "http://127.0.0.1:8000/oauth2callback", - "http://localhost:8080/" - ] - } -} \ No newline at end of file diff --git a/neuropy/neuropy/oauth.py b/neuropy/neuropy/oauth.py index 5914f32..b4d8bf0 100644 --- a/neuropy/neuropy/oauth.py +++ b/neuropy/neuropy/oauth.py @@ -1,21 +1,19 @@ """Code for return auth.""" from oauth2client.contrib.django_util.storage import DjangoORMStorage from django.contrib.auth.decorators import login_required -from oauth2client.client import flow_from_clientsecrets +from oauth2client.client import OAuth2WebServerFlow from userprofile.models import CredentialsModel from django.http import HttpResponseBadRequest from django.http import HttpResponseRedirect from oauth2client.contrib import xsrfutil from neuropy import settings -import os - -CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secret.json') - -FLOW = flow_from_clientsecrets( - CLIENT_SECRETS, +FLOW = OAuth2WebServerFlow( + client_id=settings.GOOGLE_OAUTH2_CLIENT_ID, + client_secret=settings.GOOGLE_OAUTH2_CLIENT_SECRET, scope='https://www.googleapis.com/auth/calendar', - redirect_uri='http://localhost:8000/oauth2callback' + redirect_uri='http://localhost:8000/oauth2callback', + prompt='consent' ) diff --git a/neuropy/todo/views.py b/neuropy/todo/views.py index bbeeb36..4be41e5 100644 --- a/neuropy/todo/views.py +++ b/neuropy/todo/views.py @@ -19,9 +19,8 @@ from oauth2client.contrib.django_util.storage import DjangoORMStorage from oauth2client.contrib import xsrfutil import httplib2 -import os from neuropy import settings -from oauth2client.client import flow_from_clientsecrets +from oauth2client.client import OAuth2WebServerFlow class AddTodo(LoginRequiredMixin, CreateView): @@ -122,12 +121,12 @@ def calender_update(http, event): event = service.events().update(calendarId='prmary', body=event).execute() return event -CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), '..', 'neuropy', 'client_secret.json') - -FLOW = flow_from_clientsecrets( - CLIENT_SECRETS, +FLOW = OAuth2WebServerFlow( + client_id=settings.GOOGLE_OAUTH2_CLIENT_ID, + client_secret=settings.GOOGLE_OAUTH2_CLIENT_SECRET, scope='https://www.googleapis.com/auth/calendar', - redirect_uri='http://localhost:8000/oauth2callback' + redirect_uri='http://localhost:8000/oauth2callback', + prompt='consent' ) diff --git a/neuropy/userprofile/views.py b/neuropy/userprofile/views.py index 67e0118..f4fab46 100644 --- a/neuropy/userprofile/views.py +++ b/neuropy/userprofile/views.py @@ -1,6 +1,5 @@ """Views for profile.""" -import os import httplib2 from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseRedirect @@ -13,17 +12,17 @@ from oauth2client.contrib.django_util.storage import DjangoORMStorage from oauth2client.contrib import xsrfutil from neuropy import settings -from oauth2client.client import flow_from_clientsecrets +from oauth2client.client import OAuth2WebServerFlow - -CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), '..', 'neuropy', 'client_secret.json') - -FLOW = flow_from_clientsecrets( - CLIENT_SECRETS, +FLOW = OAuth2WebServerFlow( + client_id=settings.GOOGLE_OAUTH2_CLIENT_ID, + client_secret=settings.GOOGLE_OAUTH2_CLIENT_SECRET, scope='https://www.googleapis.com/auth/calendar', - redirect_uri='http://localhost:8000/oauth2callback' + redirect_uri='http://localhost:8000/oauth2callback', + prompt='consent' ) + class ProfileView(LoginRequiredMixin, DetailView): """View for profile."""