Skip to content

Commit

Permalink
adding refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
nilbert committed Mar 14, 2018
1 parent 752ac39 commit d1c5f57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ __pycache__/
*.py[cod]
*$py.class
.idea/*
.vscode/*

# C extensions
*.so
Expand Down
27 changes: 27 additions & 0 deletions quickbooks/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,30 @@ def get_auth_header(self):
auth_header = base64.b64encode(bytes(self.client_id + ':' + self.client_secret, 'utf-8')).decode()

return 'Basic ' + auth_header

def get_new_access_tokens(self, refresh_token):

headers = {
'Accept': 'application/json',
'content-type': 'application/x-www-form-urlencoded',
'Authorization': self.get_auth_header()
}

payload = {
'refresh_token': refresh_token,
'grant_type': 'refresh_token'
}

response = requests.post(self.access_token_url, data=payload, headers=headers)
if response.status_code != 200:
return response.text

bearer_raw = json.loads(response.text)
self.x_refresh_token_expires_in = bearer_raw['x_refresh_token_expires_in']
self.access_token = bearer_raw['access_token']
self.token_type = bearer_raw['token_type']
self.refresh_token = bearer_raw['refresh_token']
self.expires_in = bearer_raw['expires_in']

if 'id_token' in bearer_raw:
self.id_token = bearer_raw['id_token']

0 comments on commit d1c5f57

Please sign in to comment.