Skip to content

Commit

Permalink
Merge pull request #329 from jstevans/patch-1
Browse files Browse the repository at this point in the history
Add config to pass on token scope-change warnings
  • Loading branch information
freakboy3742 authored Oct 13, 2022
2 parents ed3ca11 + 08bf965 commit a97737b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion xero/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ def __init__(
scope=None,
tenant_id=None,
user_agent=None,
relax_token_scope=False,
):
from xero import __version__ as VERSION

Expand All @@ -502,6 +503,7 @@ def __init__(
self.tenant_id = tenant_id # Used by BaseManager
self._oauth = None
self.scope = scope or DEFAULT_SCOPE[:]
self.relax_token_scope = relax_token_scope

if user_agent is None:
self.user_agent = (
Expand Down Expand Up @@ -566,7 +568,12 @@ def verify(self, auth_secret):
# Various different exceptions may be raised, so pass the exception
# through as XeroAccessDenied
except Exception as e:
raise XeroAccessDenied(e)
# oauthlib raises a warning when returned token scope
# is different from the client scope
if self.relax_token_scope and isinstance(e, Warning):
session.token = e.token
else:
raise XeroAccessDenied(e)
self._init_oauth(token)

def generate_url(self):
Expand Down

0 comments on commit a97737b

Please sign in to comment.