Example #1
0
 def refresh_token_to_access_token(self, refresh_token, client_info):
     endpoint = self.endpoint('access_token')
     data = Struct()
     data.grant_type = 'refresh_token'
     data.refresh_token = refresh_token.token
     data.client_id = client_info['id']
     data.client_secret = client_info['secret']
     
     # Sometime we get a 401 and retrying helps to fix that temporary glitch
     for _ in range(5):
         response = self.session.post(endpoint, data=data.get_dict())
         dump_response(response)
         if response.status_code != 401: break
         log.warning('Got 401 on token refresh. Retrying...')
     if response.status_code != 200: raise IbError('Unexpected status code on GET(12): {} {}'.format(response.status_code, response.reason), response.status_code, response.reason, response.text)
     result = Struct(response.json())
     return result
Example #2
0
 def auth_code_to_token(self, client_info, code):
     
     endpoint = self.endpoint('access_token')
     data = Struct() 
     data.grant_type = 'authorization_code'
     data.redirect_uri = client_info['redirect_uri']
     data.code = code
     data.client_id = client_info['id']
     data.client_secret = client_info['secret']
     
     log.debug('Exchanging code for access token. POST to {}'.format(endpoint))
     response = self.session.post(endpoint, data=data.get_dict())
     dump_response(response)
     if response.status_code != 200: raise IbError('Unexpected status code on POST(12): {} {}'.format(response.status_code, response.reason))
     
     oauth_token = Struct(response.json())
     return oauth_token
Example #3
0
    def auth_code_to_token(self, client_info, code):

        endpoint = self.endpoint('access_token')
        data = Struct()
        data.grant_type = 'authorization_code'
        data.redirect_uri = client_info['redirect_uri']
        data.code = code
        data.client_id = client_info['id']
        data.client_secret = client_info['secret']

        log.debug(
            'Exchanging code for access token. POST to {}'.format(endpoint))
        response = self.session.post(endpoint, data=data.get_dict())
        dump_response(response)
        if response.status_code != 200:
            raise IbError('Unexpected status code on POST(12): {} {}'.format(
                response.status_code, response.reason))

        oauth_token = Struct(response.json())
        return oauth_token
Example #4
0
    def refresh_token_to_access_token(self, refresh_token, client_info):
        endpoint = self.endpoint('access_token')
        data = Struct()
        data.grant_type = 'refresh_token'
        data.refresh_token = refresh_token.token
        data.client_id = client_info['id']
        data.client_secret = client_info['secret']

        # Sometime we get a 401 and retrying helps to fix that temporary glitch
        for _ in range(5):
            response = self.session.post(endpoint, data=data.get_dict())
            dump_response(response)
            if response.status_code != 401: break
            log.warning('Got 401 on token refresh. Retrying...')
        if response.status_code != 200:
            raise IbError(
                'Unexpected status code on GET(12): {} {}'.format(
                    response.status_code, response.reason),
                response.status_code, response.reason, response.text)
        result = Struct(response.json())
        return result