def step2_get_credentials_from_url_fragment(self, url_post_auth):
        o = urlparse.urlparse(url_post_auth)
        frag = urlparse.parse_qs(o.fragment)

        return OAuth2Credentials(frag['access_token'][0], self.client_id,
                                 self.client_secret, None, frag['expires_in'][0],
                                 self.token_uri, self.user_agent,
                                 id_token=_extract_id_token( frag['id_token'][0]))
示例#2
0
    def step12_get_token_from_client_credentials(self, http=None):

        body = urllib.urlencode({
            'grant_type': 'client_credentials',
            'client_id': self.client_id,
            'client_secret': self.client_secret,
            'response_type': 'token',
            'scope': self.scope,
        })
        headers = {
            'content-type': 'application/x-www-form-urlencoded',
        }

        if self.user_agent is not None:
            headers['user-agent'] = self.user_agent

        if http is None:
            http = httplib2.Http()

        resp, content = http.request(self.token_uri,
                                     method='POST',
                                     body=body,
                                     headers=headers)

        if resp.status == 200:
            # TODO(jcgregorio) Raise an error if simplejson.loads fails?
            d = simplejson.loads(content)
            access_token = d['access_token']
            refresh_token = d.get('refresh_token', None)
            token_expiry = None
            if 'expires_in' in d:
                token_expiry = datetime.datetime.utcnow() + datetime.timedelta(
                    seconds=int(d['expires_in']))

            if 'id_token' in d:
                d['id_token'] = _extract_id_token(d['id_token'])

            return OAuth2Credentials(access_token,
                                     self.client_id,
                                     self.client_secret,
                                     refresh_token,
                                     token_expiry,
                                     self.token_uri,
                                     self.user_agent,
                                     id_token=d.get('id_token', None))
        else:
            logging.error('Failed to retrieve access token: %s' % content)
            error_msg = 'Invalid response %s.' % resp['status']
            try:
                d = simplejson.loads(content)
                if 'error' in d:
                    error_msg = d['error']
            except:
                pass

            raise FlowExchangeError(error_msg)
示例#3
0
    def step2_get_credentials_from_url_fragment(self, url_post_auth):
        o = urlparse.urlparse(url_post_auth)
        frag = urlparse.parse_qs(o.fragment)

        return OAuth2Credentials(frag['access_token'][0],
                                 self.client_id,
                                 self.client_secret,
                                 None,
                                 frag['expires_in'][0],
                                 self.token_uri,
                                 self.user_agent,
                                 id_token=_extract_id_token(
                                     frag['id_token'][0]))
    def step12_get_token_from_client_credentials(self, http=None):

        body = urllib.urlencode({
            'grant_type': 'client_credentials',
            'client_id': self.client_id,
            'client_secret': self.client_secret,
            'response_type': 'token',
            'scope': self.scope,
            })
        headers = {
            'content-type': 'application/x-www-form-urlencoded',
        }

        if self.user_agent is not None:
          headers['user-agent'] = self.user_agent

        if http is None:
          http = httplib2.Http()

        resp, content = http.request(self.token_uri, method='POST', body=body, headers=headers)

        if resp.status == 200:
          # TODO(jcgregorio) Raise an error if simplejson.loads fails?
          d = simplejson.loads(content)
          access_token = d['access_token']
          refresh_token = d.get('refresh_token', None)
          token_expiry = None
          if 'expires_in' in d:
            token_expiry = datetime.datetime.utcnow() + datetime.timedelta(
                seconds=int(d['expires_in']))

          if 'id_token' in d:
            d['id_token'] = _extract_id_token(d['id_token'])

          return OAuth2Credentials(access_token, self.client_id,
                                   self.client_secret, refresh_token, token_expiry,
                                   self.token_uri, self.user_agent,
                                   id_token=d.get('id_token', None))
        else:
          logging.error('Failed to retrieve access token: %s' % content)
          error_msg = 'Invalid response %s.' % resp['status']
          try:
            d = simplejson.loads(content)
            if 'error' in d:
              error_msg = d['error']
          except:
            pass

          raise FlowExchangeError(error_msg)