diff --git a/docs/user-guide.rst b/docs/user-guide.rst index 3f741f6..b17d28c 100644 --- a/docs/user-guide.rst +++ b/docs/user-guide.rst @@ -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 +++++++++++++++++++++++++++++++ @@ -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 ------------- diff --git a/intuitlib/client.py b/intuitlib/client.py index 739a8d2..6a80d3d 100644 --- a/intuitlib/client.py +++ b/intuitlib/client.py @@ -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): @@ -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 """ @@ -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, @@ -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 """ @@ -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 diff --git a/intuitlib/version.py b/intuitlib/version.py index f17380e..9547e7c 100644 --- a/intuitlib/version.py +++ b/intuitlib/version.py @@ -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'