def test_decorator_from_cached_client_secrets(self): cache_mock = CacheMock() load_and_cache('client_secrets.json', 'secret', cache_mock) decorator = OAuth2DecoratorFromClientSecrets( # filename, scope, message=None, cache=None 'secret', '', cache=cache_mock) self.assertFalse(decorator._in_error)
def test_decorator_from_unfilled_client_secrets_aware(self): MESSAGE = 'File is missing' try: decorator = OAuth2DecoratorFromClientSecrets( datafile('unfilled_client_secrets.json'), scope=['foo_scope', 'bar_scope'], message=MESSAGE) except InvalidClientSecretsError: pass
def test_decorator_from_client_secrets_not_logged_in_aware(self): decorator = OAuth2DecoratorFromClientSecrets( datafile('client_secrets.json'), scope=['foo_scope', 'bar_scope'], message='NotLoggedInMessage') self.decorator = decorator self._finish_setup(decorator, user_mock=UserNotLoggedInMock) # An initial request to an oauth_aware decorated path should be a # redirect to login. response = self.app.get('/bar_path/2012/03') self.assertTrue(response.status.startswith('302')) self.assertTrue('Login' in str(response))
def test_decorator_from_client_secrets(self): decorator = OAuth2DecoratorFromClientSecrets( datafile('client_secrets.json'), scope=['foo_scope', 'bar_scope']) self._finish_setup(decorator, user_mock=UserMock) self.assertFalse(decorator._in_error) self.decorator = decorator self.test_required() http = self.decorator.http() self.assertEquals('foo_access_token', http.request.credentials.access_token) # revoke_uri is not required self.assertEqual(self.decorator._revoke_uri, 'https://accounts.google.com/o/oauth2/revoke') self.assertEqual(self.decorator._revoke_uri, self.decorator.credentials.revoke_uri)
def test_decorator_from_client_secrets_kwargs(self): decorator = OAuth2DecoratorFromClientSecrets( datafile('client_secrets.json'), scope=['foo_scope', 'bar_scope'], approval_prompt='force') self.assertTrue('approval_prompt' in decorator._kwargs)
""" name: Andrew Wang, intern company: Analytics pros project: Connect Google Analytics with AppEngine """ import json import os import webapp2 import httplib2 from apiclient.discovery import build from google.appengine.ext import webapp from oauth2client.appengine import OAuth2DecoratorFromClientSecrets decorator = OAuth2DecoratorFromClientSecrets( os.path.join(os.path.dirname(__file__), 'client_secret.json'), 'https://www.googleapis.com/auth/analytics.readonly') service = build('analytics', 'v3') import jinja2 JINJA_ENVIRONMENT = jinja2.Environment(loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), autoescape=True, extensions=['jinja2.ext.autoescape']) sampleIndex = 0 #default dataset to visualize in sidebyside samples =[ { "name":"Just 1", "data": [ {"day":1, "hour":1, "value":3} ] },
MISSING_CLIENT_SECRETS_MESSAGE = """ <h1>Warning: Please configure OAuth 2.0</h1> <p> To make this sample run you will need to populate the client_secrets.json file found at: </p> <code>%s</code> <p>You can find the Client ID and Client secret values on the API Access tab in the <a href="https://code.google.com/apis/console">APIs Console</a>. </p> """ % CLIENT_SECRETS decorator = OAuth2DecoratorFromClientSecrets( CLIENT_SECRETS, scope='https://www.googleapis.com/auth/calendar', message=MISSING_CLIENT_SECRETS_MESSAGE) service = build('calendar', 'v3') def handle_400(request, response, exception): template = JINJA_ENVIRONMENT.get_template('addEvent.html') response.write(template.render()) response.write( "<center><h3>Congratulations, you have been redirected into the fourth dimension! Jk, but seriously, you're not supposed to be here</h3></center>" ) response.write( '<center><img src="/images/404.jpg" alt="Really?"></center>')
""" import json import os from googleapiclient.discovery import build from oauth2client.appengine import OAuth2DecoratorFromClientSecrets import webapp2 # The project id whose datasets you'd like to list PROJECTID = '<your-project-id>' # Create the method decorator for oauth. decorator = OAuth2DecoratorFromClientSecrets( os.path.join(os.path.dirname(__file__), 'client_secrets.json'), scope='https://www.googleapis.com/auth/bigquery') # Create the bigquery api client service = build('bigquery', 'v2') class MainPage(webapp2.RequestHandler): # oauth_required ensures that the user goes through the OAuth2 # authorization flow before reaching this handler. @decorator.oauth_required def get(self): # This is an httplib2.Http instance that is signed with the user's # credentials. This allows you to access the BigQuery API on behalf # of the user.
import json import webapp2 import calendarListUpdate import os from google.appengine.ext import ndb from apiclient.discovery import build from google.appengine.ext import webapp from oauth2client.appengine import OAuth2DecoratorFromClientSecrets decorator = OAuth2DecoratorFromClientSecrets( os.path.join(os.path.dirname(__file__), 'client_secret_656176414432.apps.googleusercontent.com.json'), scope='https://www.googleapis.com/auth/calendar') service = build('calendar', 'v3') class Mapping(ndb.Model): title = ndb.StringProperty() htmlLink = ndb.StringProperty() reflectorList = ndb.StringProperty(repeated=True) calendarId = ndb.StringProperty() nextStartTime = ndb.StringProperty() recurringStartTime = ndb.StringProperty() location = ndb.StringProperty() latitude = ndb.FloatProperty() longitude = ndb.FloatProperty() class AddEmail(webapp2.RequestHandler):
import os from apiclient.discovery import build from oauth2client.appengine import OAuth2DecoratorFromClientSecrets oauth_decorator = OAuth2DecoratorFromClientSecrets( os.path.join(os.path.dirname(__file__), 'client_secrets.json'), 'https://www.googleapis.com/auth/cloudprint')
import logging import httplib2 from apiclient.discovery import build from oauth2client import client from apiclient import discovery from oauth2client.client import SignedJwtAssertionCredentials from oauth2client.appengine import OAuth2DecoratorFromClientSecrets import webapp2 from google.appengine.api import users from google.appengine.api import memcache from model import UserProfile decorator = OAuth2DecoratorFromClientSecrets( os.path.join(os.path.dirname(__file__), '__SECRETS__/client_secrets.json'), ['https://www.googleapis.com/auth/plus.me']) class GooglePlusHandler(webapp2.RequestHandler): @decorator.oauth_aware def get(self): user = users.get_current_user() me = user.email() if decorator.has_credentials(): service = build('plus', 'v1') result = service.people().get(userId='me').execute( http=decorator.http()) photoUrl = result['image']['url'] user_profile = UserProfile.getFromGAE(user) user_profile.photoUrl = photoUrl