Exemplo n.º 1
0
    def test_decorator_from_client_secrets_toplevel(self):
        decorator_patch = mock.patch("oauth2client.contrib.appengine.OAuth2DecoratorFromClientSecrets")

        with decorator_patch as decorator_mock:
            filename = datafile("client_secrets.json")
            appengine.oauth2decorator_from_clientsecrets(filename, scope="foo_scope")
            decorator_mock.assert_called_once_with(filename, "foo_scope", cache=None, message=None)
Exemplo n.º 2
0
    def test_decorator_from_client_secrets_toplevel(self):
        decorator_patch = mock.patch(
            'oauth2client.contrib.appengine.OAuth2DecoratorFromClientSecrets')

        with decorator_patch as decorator_mock:
            filename = datafile('client_secrets.json')
            appengine.oauth2decorator_from_clientsecrets(filename,
                                                         scope='foo_scope')
            decorator_mock.assert_called_once_with(filename,
                                                   'foo_scope',
                                                   cache=None,
                                                   message=None)
Exemplo n.º 3
0
from oauth2client.contrib import appengine
from google.appengine.api import memcache

import webapp2
import jinja2


JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
    autoescape=True,
    extensions=['jinja2.ext.autoescape'])
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')
http = httplib2.Http(memcache)

decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS,
    scope='https://www.googleapis.com/auth/drive.readonly')

class MainHandler(webapp2.RequestHandler):

  @decorator.oauth_aware
  def get(self):
    variables = {
        'url': decorator.authorize_url(),
        'has_credentials': decorator.has_credentials()
        }
    template = JINJA_ENVIRONMENT.get_template('grant.html')
    self.response.write(template.render(variables))


class AboutHandler(webapp2.RequestHandler):
Exemplo n.º 4
0
JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
    autoescape=True,
    extensions=['jinja2.ext.autoescape'])

# Client should download the credentials and deploy them with the code
# We could use KMS or Datastore, but let's keep it simple for now
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')

API_NAME = 'dfareporting'
API_VERSION = 'v2.8'
API_SCOPES = ['https://www.googleapis.com/auth/dfatrafficking']

TIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'

decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS, scope=API_SCOPES)

service = discovery.build(API_NAME, API_VERSION)


class MainHandler(webapp2.RequestHandler):

  @decorator.oauth_required
  def get(self):
    credentials = decorator.get_credentials()
    if credentials.access_token_expired:
      credentials.refresh(decorator.http())
    template = JINJA_ENVIRONMENT.get_template('templates/index.html')
    self.response.write(template.render())

Exemplo n.º 5
0
<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>
<p>
<code>%s</code>.
</p> <p>with information found on the <a
href="https://code.google.com/apis/console">APIs Console</a>.
</p>
""" % CLIENT_SECRETS

http = httplib2.Http(memcache)
service = discovery.build("plus", "v1", http=http)
decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS,
    scope='https://www.googleapis.com/auth/plus.me',
    message=MISSING_CLIENT_SECRETS_MESSAGE)


class MainHandler(webapp2.RequestHandler):
    @decorator.oauth_aware
    def get(self):
        variables = {
            'url': decorator.authorize_url(),
            'has_credentials': decorator.has_credentials()
        }
        template = JINJA_ENVIRONMENT.get_template('grant.html')
        self.response.write(template.render(variables))


class AboutHandler(webapp2.RequestHandler):
Exemplo n.º 6
0
from google.appengine.api import taskqueue

from google.appengine.ext import ndb
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler

from oauth2client import client
from oauth2client.contrib.appengine import CredentialsNDBProperty
from oauth2client.contrib import appengine


CLIENT_SECRETS = 'server/client_secret.json'
MISSING_CLIENT_SECRETS_MESSAGE = 'Missing client message'
SCOPE = 'https://www.googleapis.com/auth/drive'

decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS,
    scope=SCOPE,
    message=MISSING_CLIENT_SECRETS_MESSAGE)

http = httplib2.Http(memcache)

drive = discovery.build('drive', 'v3', http=http)


def encoded_words_to_text(encoded_words):
    result = re.match(r'=\?{1}(.+)\?{1}([B|Q])\?{1}(.+)\?{1}=', encoded_words)
    if result:
        charset, encoding, encoded_text = result.groups()
        if encoding is 'B':
            output = encoded_text.decode('base64')
        elif encoding is 'Q':
            logging.info('text encoding is quopri')
Exemplo n.º 7
0
from master import Handler

import httplib2

from googleapiclient import discovery
from oauth2client import client
from oauth2client.contrib import appengine
from google.appengine.api import memcache

SCOPE = 'https://www.googleapis.com/auth/calendar.readonly'
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')
APPLICATION_NAME = 'New Google Calendar'

http = httplib2.Http(memcache)
service = discovery.build("calendar", "v3", http=http)
decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS, scope=SCOPE, message="Missing Client Secrets")


class EventListing(Handler):
    @decorator.oauth_required
    def get(self):
        try:
            http = decorator.http()
            now = datetime.datetime.utcnow().isoformat(
            ) + 'Z'  # 'Z' indicates UTC time
            eventsResult = service.events().list(
                calendarId=
                '*****@*****.**',
                timeMin=now,
                maxResults=10,
                singleEvents=True,
Exemplo n.º 8
0
import httplib2
import os
from googleapiclient import discovery
from oauth2client import client
from oauth2client.contrib import appengine
from google.appengine.api import memcache
from googleapiclient.http import MediaIoBaseUpload, MediaIoBaseDownload

client_secret_file = 'client_secret_test.json' if os.environ.get(
    'SERVER_SOFTWARE', '').startswith('Dev') else 'client_secret.json'
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), client_secret_file)
SCOPES = 'https://www.googleapis.com/auth/drive'
APPLICATION_NAME = 'genwiki'

http = httplib2.Http(memcache)
decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS, scope=SCOPES, message='missing secret')

_dev_key = None
_wiki_id = None
_service = None


def init(dev_key, wiki_id):
    global _dev_key
    global _wiki_id
    _dev_key = dev_key
    _wiki_id = wiki_id


def get_service():
    global _service
Exemplo n.º 9
0
import os
import webapp2

from googleapiclient import discovery
from oauth2client import client
from oauth2client.contrib import appengine

from utils import template, spreadsheets
from utils.blazers import create_blazer

discoveryServiceUrl = 'https://sheets.googleapis.com/$discovery/rest?version=v4'
service = discovery.build('sheets',
                          'v4',
                          discoveryServiceUrl=discoveryServiceUrl)
decorator = appengine.oauth2decorator_from_clientsecrets(
    os.path.join(os.path.dirname(__file__), '../client_secrets.json'),
    scope='https://www.googleapis.com/auth/spreadsheets')


class AvailableBlazersHandler(webapp2.RequestHandler):
    @decorator.oauth_required
    def get(self):
        try:
            values = spreadsheets.get_values('Database!A2:D', service,
                                             decorator)

            blazers = []
            for row in values:
                if row[3] == 'No':
                    blazers.append(create_blazer(row))
Exemplo n.º 10
0
To make this sample run you will need to populate the client_secrets.json file
found at:
</p>
<p>
<code>%s</code>.
</p>
<p>with information found on the <a
href="https://code.google.com/apis/console">APIs Console</a>.
</p>
""" % CLIENT_SECRETS


http = httplib2.Http(memcache)
service = discovery.build("plus", "v1", http=http)
decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS,
    scope='https://www.googleapis.com/auth/plus.me',
    message=MISSING_CLIENT_SECRETS_MESSAGE)

class MainHandler(webapp2.RequestHandler):

  @decorator.oauth_aware
  def get(self):
    variables = {
        'url': decorator.authorize_url(),
        'has_credentials': decorator.has_credentials()
        }
    template = JINJA_ENVIRONMENT.get_template('grant.html')
    self.response.write(template.render(variables))


class AboutHandler(webapp2.RequestHandler):
Exemplo n.º 11
0
import logging
import os
import pickle
import pprint

from googleapiclient import discovery
from oauth2client import client
from oauth2client.contrib import appengine
from google.appengine.api import memcache

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')

http = httplib2.Http(memcache)
service = discovery.build("plus", "v1", http=http)
decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS,
    scope=['https://www.googleapis.com/auth/plus.me','https://www.googleapis.com/auth/plus.login'],
    message="Client secrets is missing")

template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))

# jinja_environment.globals.update(formatDate=formatDate)


def getOrCreateUser(emailAddress):

    user=User.query(User.email==emailAddress).get()

    if not user:
        http = decorator.http()
        plus_user = service.people().get(userId='me').execute(http=http)
Exemplo n.º 12
0
import pickle
import pprint

from googleapiclient import discovery
from oauth2client import client
from oauth2client.contrib import appengine
from google.appengine.api import memcache

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')

http = httplib2.Http(memcache)
service = discovery.build("plus", "v1", http=http)
decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS,
    scope=[
        'https://www.googleapis.com/auth/plus.me',
        'https://www.googleapis.com/auth/plus.login'
    ],
    message="Client secrets is missing")

template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_environment = jinja2.Environment(
    loader=jinja2.FileSystemLoader(template_dir))

# jinja_environment.globals.update(formatDate=formatDate)


def getOrCreateUser(emailAddress):

    user = User.query(User.email == emailAddress).get()
Exemplo n.º 13
0
from googleapiclient import discovery
from oauth2client import client
from oauth2client.contrib import appengine
from google.appengine.api import memcache
from google.appengine.ext import ndb

JINJA_ENVIRONMENT = jinja2.Environment(loader=jinja2.FileSystemLoader(
    os.path.dirname(__file__)),
                                       extensions=['jinja2.ext.autoescape'],
                                       autoescape=True)

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secrets.json')

http = httplib2.Http(memcache)
service = discovery.build("calendar", "v3", http=http)
decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS, scope='https://www.googleapis.com/auth/calendar')


def root_parent():
    '''Allows for strong consistency at the cost of scalability.'''
    return ndb.Key('Parent', 'default_parent')


class Event(ndb.Model):
    '''A database entry representing a single user.'''
    title = ndb.StringProperty()
    description = ndb.StringProperty()
    date = ndb.StringProperty()
    location = ndb.StringProperty()
    startTime = ndb.StringProperty()
    endTime = ndb.StringProperty()
Exemplo n.º 14
0
from googleapiclient import discovery
from oauth2client import client
from oauth2client.contrib import appengine

from utils import template, spreadsheets
from utils.blazers import create_blazer

discoveryServiceUrl = 'https://sheets.googleapis.com/$discovery/rest?version=v4'
service = discovery.build(
    'sheets',
    'v4',
    discoveryServiceUrl=discoveryServiceUrl
)
decorator = appengine.oauth2decorator_from_clientsecrets(
    os.path.join(os.path.dirname(__file__), '../client_secrets.json'),
    scope='https://www.googleapis.com/auth/spreadsheets'
)


class AvailableBlazersHandler(webapp2.RequestHandler):
    @decorator.oauth_required
    def get(self):
        try:
            values = spreadsheets.get_values(
                'Database!A2:D',
                service,
                decorator
            )

            blazers = []
            for row in values:
Exemplo n.º 15
0
import os
from googleapiclient import discovery
from oauth2client import client
from oauth2client.contrib import appengine
from google.appengine.api import memcache
from googleapiclient.http import MediaIoBaseUpload, MediaIoBaseDownload


client_secret_file = 'client_secret_test.json' if os.environ.get('SERVER_SOFTWARE', '').startswith('Dev') else 'client_secret.json'
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), client_secret_file)
SCOPES = 'https://www.googleapis.com/auth/drive'
APPLICATION_NAME = 'genwiki'

http = httplib2.Http(memcache)
decorator = appengine.oauth2decorator_from_clientsecrets(
    CLIENT_SECRETS,
    scope=SCOPES,
    message='missing secret')

_dev_key = None
_wiki_id = None
_service = None


def init(dev_key, wiki_id):
    global _dev_key
    global _wiki_id
    _dev_key = dev_key
    _wiki_id = wiki_id


def get_service():