Skip to content

Commit

Permalink
Add support for revoking QBO refresh token (#17)
Browse files Browse the repository at this point in the history
* Add support for revoking QBO refresh token

* remove commented code
  • Loading branch information
ashwin1111 authored Sep 14, 2022
1 parent d9f5bfa commit 871c73a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __pycache__/
# Test Files
usage.py
test_credentials.json
scripts/

# C extensions
*.so
Expand Down
5 changes: 3 additions & 2 deletions qbosdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Quickbooks Online init
"""
from .qbosdk import QuickbooksOnlineSDK
from .qbosdk import QuickbooksOnlineSDK, revoke_refresh_token
from.exceptions import *

__all__ = [
Expand All @@ -14,7 +14,8 @@
'NoPrivilegeError',
'WrongParamsError',
'NotFoundItemError',
'InternalServerError'
'InternalServerError',
'revoke_refresh_token'
]

name = "qbosdk"
25 changes: 25 additions & 0 deletions qbosdk/qbosdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class QuickbooksOnlineSDK:
Quickbooks Online SDK
"""
TOKEN_URL = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'
TOKEN_REVOKE_URL = 'https://developer.API.intuit.com/v2/oauth2/tokens/revoke'

def __init__(self, client_id: str, client_secret: str,
refresh_token: str, realm_id: str, environment: str):
Expand Down Expand Up @@ -155,3 +156,27 @@ def __get_access_token(self):

else:
raise QuickbooksOnlineSDKError('Error: {0}'.format(response.status_code), response.text)

def revoke_refresh_token(refresh_token: str, client_id: str, client_secret: str):
api_data = {
'token': refresh_token
}

auth = '{0}:{1}'.format(client_id, client_secret)
auth = base64.b64encode(auth.encode('utf-8'))

request_header = {
'Accept': 'application/json',
'Content-type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic {0}'.format(
str(auth.decode())
)
}

response = requests.post(url=QuickbooksOnlineSDK.TOKEN_REVOKE_URL, data=api_data, headers=request_header)

if response.status_code == 200:
return {'message': 'Token revoked successfully'}

else:
raise QuickbooksOnlineSDKError('Error: {0}'.format(response.status_code), response.text)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='qbosdk',
version='0.13.2',
version='0.14.0',
author='Shwetabh Kumar',
author_email='shwetabh.kumar@fyle.in',
description='Python SDK for accessing Quickbooks Online APIs',
Expand Down

0 comments on commit 871c73a

Please sign in to comment.