Skip to content

Commit 0921c8a

Browse files
author
Santiago Romero
committed
allow id_token to be optional for OAuth2Token.update_token, since it's not omitted when the "openid" scope is not used
Signed-off-by: Santiago Romero <[email protected]>
1 parent 89558c0 commit 0921c8a

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ def oauth2_token(
127127
"token_type": "Bearer",
128128
}
129129

130+
@pytest.fixture()
131+
def oauth2_token_without_id_token(
132+
xero_access_token,
133+
xero_refresh_token,
134+
xero_scope,
135+
xero_expires_in,
136+
xero_expires_at,
137+
):
138+
return {
139+
"access_token": xero_access_token,
140+
"expires_at": xero_expires_at,
141+
"expires_in": xero_expires_in,
142+
"refresh_token": xero_refresh_token,
143+
"scope": xero_scope,
144+
"token_type": "Bearer",
145+
}
146+
130147

131148
@pytest.fixture()
132149
def oauth2_refresh_token(oauth2_token, xero_refresh_token):

tests/test_api_client/test_oauth2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,22 @@ def test_auth2_call_refresh_token_api(oauth2_refresh_token):
205205
assert call_kwargs == {}
206206
assert new_token is token
207207

208+
def test_auth2_call_refresh_token_api_without_id_token(oauth2_token_without_id_token):
209+
# Given valid refresh token and client credentials without using OpenID scope (id_token absent)
210+
oauth2_token = OAuth2Token()
211+
oauth2_token.update_token(**oauth2_token_without_id_token)
212+
token = {}
213+
token_api = FakeClass()
214+
token_api.refresh_token = FakeMethod(return_value=token)
215+
# When refresh token API endpoint called
216+
new_token = oauth2_token.call_refresh_token_api(token_api)
217+
# Then new oauth2 token received
218+
assert len(token_api.refresh_token.calls) == 1
219+
call_args, call_kwargs = token_api.refresh_token.calls[0]
220+
assert call_args == (oauth2_token.refresh_token, oauth2_token.scope)
221+
assert call_kwargs == {}
222+
assert new_token is token
223+
208224

209225
def test_token_api_refresh_token(
210226
xero_client_id, xero_client_secret, xero_scope, vcr, vcr_cassette_name

xero_python/api_client/oauth2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def update_token(
179179
expires_at,
180180
expires_in,
181181
token_type,
182-
id_token,
182+
id_token=None,
183183
):
184184
"""
185185
Set new auth2 token details
@@ -189,7 +189,7 @@ def update_token(
189189
:param expires_at: float timestamp
190190
:param expires_in: number
191191
:param token_type: str
192-
:param id_token: str
192+
:param id_token: str (optional)
193193
"""
194194
self.access_token = access_token
195195
self.expires_at = expires_at

0 commit comments

Comments
 (0)