Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1c5f57

Browse files
committed
adding refresh token
1 parent 752ac39 commit d1c5f57

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55
.idea/*
6+
.vscode/*
67

78
# C extensions
89
*.so

quickbooks/auth.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,30 @@ def get_auth_header(self):
261261
auth_header = base64.b64encode(bytes(self.client_id + ':' + self.client_secret, 'utf-8')).decode()
262262

263263
return 'Basic ' + auth_header
264+
265+
def get_new_access_tokens(self, refresh_token):
266+
267+
headers = {
268+
'Accept': 'application/json',
269+
'content-type': 'application/x-www-form-urlencoded',
270+
'Authorization': self.get_auth_header()
271+
}
272+
273+
payload = {
274+
'refresh_token': refresh_token,
275+
'grant_type': 'refresh_token'
276+
}
277+
278+
response = requests.post(self.access_token_url, data=payload, headers=headers)
279+
if response.status_code != 200:
280+
return response.text
281+
282+
bearer_raw = json.loads(response.text)
283+
self.x_refresh_token_expires_in = bearer_raw['x_refresh_token_expires_in']
284+
self.access_token = bearer_raw['access_token']
285+
self.token_type = bearer_raw['token_type']
286+
self.refresh_token = bearer_raw['refresh_token']
287+
self.expires_in = bearer_raw['expires_in']
288+
289+
if 'id_token' in bearer_raw:
290+
self.id_token = bearer_raw['id_token']

0 commit comments

Comments
 (0)