Exemplo n.º 1
0
 def _refresh_token_flow(self):
     """Given a refresh token, obtain a new access token."""
     url = '%s%s/oauth2/token' % (self.scheme, self.site)
     options = {
         'grant_type': 'refresh_token',
         'client_id': self.options.get('client_id'),
         'client_secret': self.options.get('client_secret'),
         'refresh_token': self.options.get('refresh_token')
     }
     options.update({
         'verify_ssl': self.options.get('verify_ssl', True),
         'proxies': self.options.get('proxies', None)
     })
     self.token = wrapped_resource(
         make_request('post', url, options))
     self.access_token = self.token.access_token
Exemplo n.º 2
0
    def _request(self, method, resource, **kwargs):
        """Given an HTTP method, a resource name and kwargs, construct a
        request and return the response.
        """
        url = self._resolve_resource_name(resource)

        if hasattr(self, 'access_token'):
            kwargs.update(dict(access_token=self.access_token))
        if hasattr(self, 'client_id'):
            kwargs.update(dict(client_id=self.client_id))

        kwargs.update({
            'verify_ssl': self.options.get('verify_ssl', True),
            'proxies': self.options.get('proxies', None)
        })
        return wrapped_resource(make_request(method, url, kwargs))
Exemplo n.º 3
0
 def _credentials_flow(self):
     """Given a username and password, obtain an access token."""
     url = '%s%s/oauth2/token' % (self.scheme, self.site)
     options = {
         'client_id': self.options.get('client_id'),
         'client_secret': self.options.get('client_secret'),
         'username': self.options.get('username'),
         'password': self.options.get('password'),
         'scope': getattr(self, 'scope', ''),
         'grant_type': 'password'
     }
     options.update({
         'verify_ssl': self.options.get('verify_ssl', True),
         'proxies': self.options.get('proxies', None)
     })
     self.token = wrapped_resource(
         make_request('post', url, options))
     self.access_token = self.token.access_token
Exemplo n.º 4
0
 def exchange_token(self, code):
     """Given the value of the code parameter, request an access token."""
     url = '%s%s/oauth2/access_token' % (self.scheme, self.site)
     options = {
         'grant_type': 'authorization_code',
         'redirect_uri': self.options.get('redirect_uri'),
         'client_id': self.options.get('client_id'),
         'client_secret': self.options.get('client_secret'),
         'code': code,
     }
     options.update({
         'verify_ssl': self.options.get('verify_ssl', True),
         'proxies': self.options.get('proxies', None)
     })
     self.token = wrapped_resource(
         make_request('post', url, options))
     self.access_token = self.token.access_token
     return self.token