Example #1
0
def buzz_login():
  buzz_discovery = build("buzz", "v1").auth_discovery()

  flow = FlowThreeLegged(buzz_discovery,
                         consumer_key='anonymous',
                         consumer_secret='anonymous',
                         user_agent='google-api-client-python-buzz-cmdline/1.0',
                         domain='anonymous',
                         scope='https://www.googleapis.com/auth/buzz',
                         xoauth_displayname='oacurl.py')

  authorize_url = flow.step1_get_authorize_url()

  print 'Go to the following link in your browser:'
  print authorize_url
  print

  accepted = 'n'
  while accepted.lower() == 'n':
      accepted = raw_input('Have you authorized me? (y/n) ')
  verification = raw_input('What is the verification code? ').strip()

  credentials = flow.step2_exchange(verification)
  path = os.path.expanduser('~/.oacurl.properties')
  save_properties('anonymous', 'anonymous', credentials.token.key, credentials.token.secret,path)
Example #2
0
 def _handle_start(self, request):
     discovery = {
         'request': {
             'url': self.request_token_url,
             'parameters': {
                 },
             },
         'authorize': {
             'url': self.authorize_url,
             'parameters': {
                 'oauth_token': {
                     'required': True,
                     },
                 },
             },
         'access': {
             'url': self.access_token_url,
             'parameters': {
                 },
             },
         }
     self.flow = FlowThreeLegged(
         discovery=discovery,
         consumer_key=self.config.client_id,
         consumer_secret=self.config.client_secret,
         user_agent='aeauth'
     )
     callback_url = self.get_callback_url(
         request.host_url, self.provider)
     authorize_url = self.flow.step1_get_authorize_url(
         oauth_callback=callback_url)
     return authorize_url
Example #3
0
    def handle_request(self, req):
        self.callback_uri = '{0}{1}/{2}/callback'.format(
            req.host_url, self.config['base_uri'], req.provider)
        self.session_key = '_auth_strategy:{0}'.format(req.provider)

        discovery = {
            'request': {
                'url': self.options['request_token_uri'],
                'parameters': {},
            },
            'authorize': {
                'url': self.options['authorize_uri'],
                'parameters': {
                    'oauth_token': {
                        'required': True,
                    },
                },
            },
            'access': {
                'url': self.options['access_token_uri'],
                'parameters': {},
            },
        }
        req.flow = FlowThreeLegged(
            discovery=discovery,
            consumer_key=req.provider_config.get('client_id'),
            consumer_secret=req.provider_config.get('client_secret'),
            user_agent='EngineAuth')
        if not req.provider_params:
            return self.start(req)
        else:
            return self.callback(req)
Example #4
0
def main():
    signal.alarm(47)
    storage = Storage('latitude.dat')
    credentials = storage.get()
    if credentials is None or credentials.invalid == True:
        auth_discovery = build("latitude", "v1").auth_discovery()
        flow = FlowThreeLegged(
            auth_discovery,
            # You MUST have a consumer key and secret tied to a
            # registered domain to use the latitude API.
            #
            # https://www.google.com/accounts/ManageDomains
            consumer_key='west.spy.net',
            consumer_secret='kF52E2QkcMYeWI5JBxUdqHkE',
            user_agent='google-api-client-python-latitude/1.0',
            domain='west.spy.net',
            scope='https://www.googleapis.com/auth/latitude',
            xoauth_displayname='Google API Latitude Example',
            location='all',
            granularity='best')

        credentials = run(flow, storage)

    http = httplib2.Http()
    http = credentials.authorize(http)

    service = build("latitude", "v1", http=http)

    more = True
    max_time = ""
    args = {'max_results': '1000', 'granularity': 'best'}

    # See if we're picking up from somewhere...
    try:
        lastKey = list(
            DB.view('_all_docs', limit=1, descending=True, startkey='9'))[0].id
        args['min_time'] = lastKey
        print "Resuming since", lastKey
    except IndexError:
        print "Not resuming."

    while more:
        r = service.location().list(**args).execute()['items']
        store(r)
        more = len(r) == 1000

        print "Got %d records from %s - %s" % (len(r), ts(r[-1]), ts(r[0]))
        args['max_time'] = r[-1]['timestampMs']
Example #5
0
def main():
    storage = Storage('latitude.dat')
    credentials = storage.get()
    if credentials is None or credentials.invalid == True:
        auth_discovery = build("latitude", "v1").auth_discovery()
        flow = FlowThreeLegged(
            auth_discovery,
            # You MUST have a consumer key and secret tied to a
            # registered domain to use the latitude API.
            #
            # https://www.google.com/accounts/ManageDomains
            consumer_key='REGISTERED DOMAIN NAME',
            consumer_secret='KEY GIVEN DURING REGISTRATION',
            user_agent='google-api-client-python-latitude/1.0',
            domain='REGISTERED DOMAIN NAME',
            scope='https://www.googleapis.com/auth/latitude',
            xoauth_displayname='Google API Latitude Example',
            location='current',
            granularity='city')

        credentials = run(flow, storage)

    http = httplib2.Http()
    http = credentials.authorize(http)

    service = build("latitude", "v1", http=http)

    body = {
        "data": {
            "kind": "latitude#location",
            "latitude": 37.420352,
            "longitude": -122.083389,
            "accuracy": 130,
            "altitude": 35
        }
    }
    print service.currentLocation().insert(body=body).execute()
Example #6
0
class OAuthUserProfile(ProviderUserProfile):

    request_token_url = None
    access_token_url = None
    authorize_url = None

    # this is Python specific, but that's ok because it's short lived.
    flow = ndb.PickleProperty()

    def http(self):
        if not self.credentials.invalid:
            return self.credentials.authorize(httplib2.Http())
        return None

    def service(self, **kwargs):
        raise NotImplementedError()

    def get_url(self, url):
        res, results = self.http().request(url)
        if res.status is not 200:
            raise Exception(message=u'There was an error contacting the '\
                                          u'provider. Please try again.')
        return json.loads(results)

    def _handle_start(self, request):
        discovery = {
            'request': {
                'url': self.request_token_url,
                'parameters': {
                    },
                },
            'authorize': {
                'url': self.authorize_url,
                'parameters': {
                    'oauth_token': {
                        'required': True,
                        },
                    },
                },
            'access': {
                'url': self.access_token_url,
                'parameters': {
                    },
                },
            }
        self.flow = FlowThreeLegged(
            discovery=discovery,
            consumer_key=self.config.client_id,
            consumer_secret=self.config.client_secret,
            user_agent='aeauth'
        )
        callback_url = self.get_callback_url(
            request.host_url, self.provider)
        authorize_url = self.flow.step1_get_authorize_url(
            oauth_callback=callback_url)
        return authorize_url

    def _handle_callback(self, request):
        if self.flow is None:
            raise Exception(message=u'And Error has occurred. '\
                                          u'Please try again.')
        try:
            self.credentials = self.flow.step2_exchange(request.params)
        except Exception, e:
            import logging
            logging.error(e)
            raise Exception(message=u'And Error has occurred. '\
                                          u'Please try again.')
        self.set_person_raw()
        try:
            self.set_person()
            self.set_key()
        except Exception, e:
            import logging
            logging.error(e)