Open benefacto opened 2 years ago
I encountered this issue. My work around was to convert the scopes in the json to a list.
e,g. change "scope": "email profile openid accounting.transactions offline_access" to "scope": ["email", "profile", "openid", "accounting.transactions", "offline_access"]
Seems to work fine now.
This can't be intended behavior, right? When undergoing Xero's own oauth2 flow, the token is returned with it's scopes as a space delimited string, which causes refreshing to never work? I just came across this issue and after looking at the source code, it's as simple as relaxing the check on the scope value in can_refresh_access_token.
def can_refresh_access_token(self):
"""
Check current instance has all data required to perform refresh token API call.
:return: bool
"""
return (
self.refresh_token
and isinstance(self.scope, (list, tuple))
and self.client_id
and self.client_secret
)
I would make a push request to change that one line to and isinstance(self.scope, (list, tuple, str))
but to be honest I'm not sure what the original check might be guarding against. Regardless, it's wild that this is still an unexplained issue years later.
I'm pretty surprised that this is still an issue after so long. I'm not a maintainer, nor have touched this SDK in years, but I tried to trigger the Jira ticket creation GitHub action to make this issue more visible, though it looks like it only is triggered when new issues are created.
@j-osephlong I remember when I last spoke to one of the former maintainers, Xero was lacking sufficient resources to maintain the Python SDK and would welcome contributions. It looks like most pull requests get merged.
That or perhaps one of the current maintainers could look into this? @manishT72 @Raghunath-S-S-J
First ever pull request! Wish me luck.
Which version of the SDK are you using?
1.10.0
A quick summary and/or background
Discovered this issue when debugging refresh token issues with @RettBehrens . If
scope
is passed as astr
(or another type) rather than alist
in the token set to the helper methodstore_xero_oauth2_token
, thenrefresh_oauth2_token
will returnNone
rather than the refreshed token set.Steps to reproduce
scopes
as a space delimited string within the token set passed to anstore_xero_oauth2_token
refresh_oauth2_token
refresh_oauth2_token
isNone
What you expected would happen
scopes
as a space delimited string within the token set passed to anstore_xero_oauth2_token
refresh_oauth2_token
can_refresh_access_token
raises an error describing why the token cannot be refreshed: in this case, the error should state that scope must be alist
ofstr
What actually happens
scopes
as a space delimited string within the token set passed to anstore_xero_oauth2_token
refresh_oauth2_token
refresh_oauth2_token
is not needed sincestore_xero_oauth2_token
is called internally withinrefresh_oauth2_token
, the issue is invisible and a silent failure occurs