Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/user-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ The `auth_code` from URL params from Step 2 is used to get bearer tokens. Option

auth_client.get_bearer_token(auth_code, realm_id=realm_id)

After successful response, `access_token`, `refresh_token`, etc properties of `auth_client` object are set.
To include the refresh token hard expiry in the response, pass `include_refresh_token_hard_expires_in=True`. The response will contain the `x_refresh_token_hard_expires_in` attribute indicating the refresh token lifespan (in seconds) ::

auth_client.get_bearer_token(auth_code, realm_id=realm_id, include_refresh_token_hard_expires_in=True)

After successful response, `access_token`, `refresh_token`, `expires_in`, `x_refresh_token_expires_in`, `x_refresh_token_hard_expires_in`, etc properties of `auth_client` object are set.

Step 4 (OAuth): Sample API Call
+++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -71,6 +75,10 @@ Or by passing the `refresh_token` as a parameter: ::

auth_client.refresh(refresh_token='EnterRefreshTokenHere')

To include the refresh token hard expiry in the response, pass `include_refresh_token_hard_expires_in=True` ::

auth_client.refresh(include_refresh_token_hard_expires_in=True)

Revoke Tokens
-------------

Expand Down
15 changes: 13 additions & 2 deletions intuitlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(self, client_id, client_secret, redirect_uri, environment, state_to
self.expires_in = None
self.refresh_token = refresh_token
self.x_refresh_token_expires_in = None
self.x_refresh_token_hard_expires_in = None
self.id_token = id_token

def setAuthorizeURLs(self, urlObject):
Expand Down Expand Up @@ -107,11 +108,13 @@ def get_authorization_url(self, scopes, state_token=None):

return '?'.join([self.auth_endpoint, urlencode(url_params)])

def get_bearer_token(self, auth_code, realm_id=None):
def get_bearer_token(self, auth_code, realm_id=None, include_refresh_token_hard_expires_in=False):
"""Gets access_token and refresh_token using authorization code

:param auth_code: Authorization code received from redirect_uri
:param realm_id: Realm ID/Company ID of the QBO company
:param include_refresh_token_hard_expires_in: When True, the response will contain the
x_refresh_token_hard_expires_in attribute indicating the refresh token lifespan
:raises `intuitlib.exceptions.AuthClientError`: if response status != 200
"""

Expand All @@ -124,6 +127,9 @@ def get_bearer_token(self, auth_code, realm_id=None):
'Authorization': get_auth_header(self.client_id, self.client_secret)
}

if include_refresh_token_hard_expires_in:
headers['x-include-refresh-token-hard-expires-in'] = 'true'

body = {
'grant_type': 'authorization_code',
'code': auth_code,
Expand All @@ -132,10 +138,12 @@ def get_bearer_token(self, auth_code, realm_id=None):

send_request('POST', self.token_endpoint, headers, self, body=urlencode(body), session=self)

def refresh(self, refresh_token=None):
def refresh(self, refresh_token=None, include_refresh_token_hard_expires_in=False):
"""Gets fresh access_token and refresh_token

:param refresh_token: Refresh Token
:param include_refresh_token_hard_expires_in: When True, the response will contain the
x_refresh_token_hard_expires_in attribute indicating the refresh token lifespan
:raises ValueError: if Refresh Token value not specified
:raises `intuitlib.exceptions.AuthClientError`: if response status != 200
"""
Expand All @@ -149,6 +157,9 @@ def refresh(self, refresh_token=None):
'Authorization': get_auth_header(self.client_id, self.client_secret)
}

if include_refresh_token_hard_expires_in:
headers['x-include-refresh-token-hard-expires-in'] = 'true'

body = {
'grant_type': 'refresh_token',
'refresh_token': token
Expand Down
2 changes: 1 addition & 1 deletion intuitlib/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '1.2.6'
__version__ = '1.2.7'