Skip to content

Commit

Permalink
refresh_oauth2_token silently fails if can_refresh_access_token fails…
Browse files Browse the repository at this point in the history
… type validation
  • Loading branch information
vigneshk-tw committed Nov 29, 2024
1 parent 64e438b commit 35c3923
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/v1/accounting/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6339,7 +6339,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="Accounting"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="Accounting"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="Accounting"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="Accounting"><a href="#api-Accounting">Methods</a></li>
<li data-group="Accounting" data-name="createAccount" class="">
<a href="#api-Accounting-createAccount">createAccount</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/appstore/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="AppStore"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="AppStore"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="AppStore"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="AppStore"><a href="#api-AppStore">Methods</a></li>
<li data-group="AppStore" data-name="getSubscription" class="">
<a href="#api-AppStore-getSubscription">getSubscription</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="Asset"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="Asset"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="Asset"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="Asset"><a href="#api-Asset">Methods</a></li>
<li data-group="Asset" data-name="createAsset" class="">
<a href="#api-Asset-createAsset">createAsset</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="Files"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="Files"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="Files"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="Files"><a href="#api-Files">Methods</a></li>
<li data-group="Files" data-name="createFileAssociation" class="">
<a href="#api-Files-createFileAssociation">createFileAssociation</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/finance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2737,7 +2737,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="Finance"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="Finance"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="Finance"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="Finance"><a href="#api-Finance">Methods</a></li>
<li data-group="Finance" data-name="getAccountingActivityAccountUsage" class="">
<a href="#api-Finance-getAccountingActivityAccountUsage">getAccountingActivityAccountUsage</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/payroll-au/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3412,7 +3412,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="PayrollAu"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="PayrollAu"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="PayrollAu"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="PayrollAu"><a href="#api-PayrollAu">Methods</a></li>
<li data-group="PayrollAu" data-name="approveLeaveApplication" class="">
<a href="#api-PayrollAu-approveLeaveApplication">approveLeaveApplication</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/payroll-nz/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4031,7 +4031,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="PayrollNz"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="PayrollNz"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="PayrollNz"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="PayrollNz"><a href="#api-PayrollNz">Methods</a></li>
<li data-group="PayrollNz" data-name="approveTimesheet" class="">
<a href="#api-PayrollNz-approveTimesheet">approveTimesheet</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/payroll-uk/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3517,7 +3517,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="PayrollUk"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="PayrollUk"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="PayrollUk"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="PayrollUk"><a href="#api-PayrollUk">Methods</a></li>
<li data-group="PayrollUk" data-name="approveTimesheet" class="">
<a href="#api-PayrollUk-approveTimesheet">approveTimesheet</a>
Expand Down
2 changes: 1 addition & 1 deletion docs/v1/projects/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@
<nav id="scrollingNav">
<ul class="sidenav nav nav-list">
<li class="nav-header" data-group="Project"><strong>SDK: </strong><span id='sdk-name'></span></li>
<li class="nav-header" data-group="Project"><strong>VSN: </strong>6.3.0</li>
<li class="nav-header" data-group="Project"><strong>VSN: </strong>6.3.1</li>
<li class="nav-header" data-group="Project"><a href="#api-Project">Methods</a></li>
<li data-group="Project" data-name="createProject" class="">
<a href="#api-Project-createProject">createProject</a>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ def read_file(filename):
keywords="xero python sdk API oAuth",
name="xero_python",
packages=find_packages(include=["xero_python", "xero_python.*"]),
version="6.3.0",
version="6.3.1",
)
44 changes: 44 additions & 0 deletions tests/test_api_client/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,50 @@ def test_auth2_refresh_access_token():
assert oauth2_token.access_token == new_token["access_token"]
assert oauth2_token.refresh_token == new_token["refresh_token"]

def test_auth2_refresh_access_token_having_scope_as_string():
# given OAuth2Token with expired access_token
api_client = FakeClass()
api_client.set_oauth2_token = FakeMethod()
refresh_token = "refresh-token-value"
scope = (
"email profile openid accounting.reports.read "
"accounting.attachments.read accounting.settings "
"accounting.settings.read accounting.attachments "
"accounting.transactions accounting.journals.read "
"accounting.transactions.read accounting.contacts "
"accounting.contacts.read offline_access"
)
new_token = {
"id_token": "new-id-token-value",
"access_token": "new-access-token-value",
"expires_in": 1800,
"expires_at": time.time() + 1800,
"token_type": "Bearer",
"refresh_token": "new-refresh-token-value",
"scope": scope,
}
oauth2_token = OAuth2Token(client_id="client_id", client_secret="client_secret")
oauth2_token.refresh_token = refresh_token
oauth2_token.scope = scope
oauth2_token.fetch_access_token = FakeMethod(return_value=new_token)
# When refreshing access_token
assert oauth2_token.refresh_access_token(api_client=api_client)
# Then expected set new token function called
assert len(oauth2_token.fetch_access_token.calls) == 1
assert len(api_client.set_oauth2_token.calls) == 1
call_args, call_kwargs = api_client.set_oauth2_token.calls[0]
assert call_args == (new_token,)
assert call_kwargs == {}
# Then expected new valid access and refresh tokens set on oauth2_token
assert oauth2_token.expires_at == new_token["expires_at"]
assert oauth2_token.is_access_token_valid()
assert oauth2_token.id_token == new_token["id_token"]
assert oauth2_token.expires_in == new_token["expires_in"]
assert oauth2_token.token_type == new_token["token_type"]
assert oauth2_token.scope == new_token["scope"]
assert oauth2_token.access_token == new_token["access_token"]
assert oauth2_token.refresh_token == new_token["refresh_token"]


def test_auth2_fetch_access_token():
# Given OAuth2Token with valid refresh_token
Expand Down
2 changes: 1 addition & 1 deletion xero_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Xero Developer API"""
__email__ = "[email protected]"
__version__ = "6.3.0"
__version__ = "6.3.1"
2 changes: 1 addition & 1 deletion xero_python/api_client/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def can_refresh_access_token(self):
"""
return (
self.refresh_token
and isinstance(self.scope, (list, tuple))
and isinstance(self.scope, (list, tuple, str))
and self.client_id
and self.client_secret
)
Expand Down
2 changes: 1 addition & 1 deletion xero_python/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ These endpoints are related to managing authentication tokens and identity for X
The `xero_python` package is automatically generated by the [XeroAPI SDK 2.0 Codegen](https://github.com/xero-github/xeroapi-sdk-codegen) project:

- API version: 6.3.0
- Package version: 6.3.0
- Package version: 6.3.1
- Build package: org.openapitools.codegen.languages.PythonClientCodegen
For more information, please visit [https://developer.xero.com](https://developer.xero.com)

Expand Down

0 comments on commit 35c3923

Please sign in to comment.