コード例 #1
0
def retrieve_discovery_doc(serviceName,
                           version,
                           discoveryServiceUrl=DISCOVERY_URI):
    params = {'api': serviceName, 'apiVersion': version}
    requested_url = uritemplate.expand(discoveryServiceUrl, params)

    # REMOTE_ADDR is defined by the CGI spec [RFC3875] as the environment
    # variable that contains the network address of the client sending the
    # request. If it exists then add that to the request for the discovery
    # document to avoid exceeding the quota on discovery requests.
    if 'REMOTE_ADDR' in os.environ:
        requested_url = _add_query_parameter(requested_url, 'userIp',
                                             os.environ['REMOTE_ADDR'])

    http = httplib2.Http()
    resp, content = http.request(requested_url)
    if resp.status >= 400:
        raise HttpError(resp, content, uri=requested_url)

    try:
        service = json.loads(content)
    except ValueError:
        raise InvalidJsonError('Bad JSON: %s from %s.' %
                               (content, requested_url))

    # We return content instead of the JSON deserialized service because
    # build_from_document() consumes a string rather than a dictionary.
    return content
コード例 #2
0
ファイル: client.py プロジェクト: slackpad/hashtagtodo-open
def retrieve_discovery_doc(serviceName, version,
                           discoveryServiceUrl=DISCOVERY_URI):
    params = {'api': serviceName, 'apiVersion': version}
    requested_url = uritemplate.expand(discoveryServiceUrl, params)

    # REMOTE_ADDR is defined by the CGI spec [RFC3875] as the environment
    # variable that contains the network address of the client sending the
    # request. If it exists then add that to the request for the discovery
    # document to avoid exceeding the quota on discovery requests.
    if 'REMOTE_ADDR' in os.environ:
        requested_url = _add_query_parameter(requested_url, 'userIp',
                                             os.environ['REMOTE_ADDR'])

    http = httplib2.Http()
    resp, content = http.request(requested_url)
    if resp.status >= 400:
        raise HttpError(resp, content, uri=requested_url)

    try:
        service = json.loads(content)
    except ValueError:
        raise InvalidJsonError(
            'Bad JSON: %s from %s.' % (content, requested_url))

    # We return content instead of the JSON deserialized service because
    # build_from_document() consumes a string rather than a dictionary.
    return content
コード例 #3
0
            def get(self):
                error = self.request.get('error')
                if error:
                    errormsg = self.request.get('error_description', error)
                    self.response.out.write(
                        'The authorization request failed: %s' %
                        _safe_html(errormsg))
                else:
                    user = users.get_current_user()
                    decorator._create_flow(self)
                    credentials = decorator.flow.step2_exchange(
                        self.request.params)
                    StorageByKeyName(CredentialsModel, user.user_id(),
                                     'credentials').put(credentials)
                    redirect_uri = _parse_state_value(
                        str(self.request.get('state')), user)

                    if decorator._token_response_param and credentials.token_response:
                        resp_json = simplejson.dumps(
                            credentials.token_response)
                        redirect_uri = discovery._add_query_parameter(
                            redirect_uri, decorator._token_response_param,
                            resp_json)

                    self.redirect(redirect_uri)
コード例 #4
0
ファイル: domain.py プロジェクト: djpetti/hd-domain
  def __get_discovery_doc(self, service_name, version, http=None,
                            discovery_service_url=DISCOVERY_URI):
    # Returned a cached copy if we have it.
    cached = memcache.get("discovery_doc")
    if cached:
      return cached
    logging.info("Cache miss in discovery document.")

    params = {'api': service_name, 'apiVersion': version}
    requested_url = uritemplate.expand(discovery_service_url, params)

    # REMOTE_ADDR is defined by the CGI spec [RFC3875] as the environment
    # variable that contains the network address of the client sending the
    # request. If it exists then add that to the request for the discovery
    # document to avoid exceeding the quota on discovery requests.
    if 'REMOTE_ADDR' in os.environ:
      requested_url = _add_query_parameter(requested_url, 'userIp',
                                          os.environ['REMOTE_ADDR'])

    http = http or httplib2.Http()
    resp, content = http.request(requested_url)
    if resp.status >= 400:
      raise HttpError(resp, content, uri=requested_url)

    # Store it in the memcache.
    memcache.set("discovery_doc", content, time=60 * 60 * 24)

    return content
コード例 #5
0
      def get(self):
        error = self.request.get('error')
        if error:
          errormsg = self.request.get('error_description', error)
          self.response.out.write(
              'The authorization request failed: %s' % _safe_html(errormsg))
        else:
          user = users.get_current_user()
          decorator._create_flow(self)
          credentials = decorator.flow.step2_exchange(self.request.params)
          StorageByKeyName(
              CredentialsModel, user.user_id(), 'credentials').put(credentials)
          redirect_uri = _parse_state_value(str(self.request.get('state')),
                                            user)

          if decorator._token_response_param and credentials.token_response:
            resp_json = simplejson.dumps(credentials.token_response)
            redirect_uri = discovery._add_query_parameter(
              redirect_uri, decorator._token_response_param, resp_json)

          self.redirect(redirect_uri)