Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing an optional authorisation event id to get_tenants. #309

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ def json_fct():
self.assertEqual(
tenants, [{"id": "1", "tenantId": "12345", "tenantType": "ORGANISATION"}]
)
tenants = credentials.get_tenants(auth_event_id="b71db552-68ff-4d80-a824-7544e5ccad28")
self.assertEqual(r_get.mock_calls[-1].args[0].split('?authEventId=')[1], "b71db552-68ff-4d80-a824-7544e5ccad28")

@patch("xero.auth.OAuth2Credentials.get_tenants")
def test_set_default_tenant(self, get_tenants):
Expand Down
8 changes: 7 additions & 1 deletion xero/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,18 @@ def refresh(self):
self._init_oauth(token)
return token

def get_tenants(self):
def get_tenants(self, auth_event_id=None):
"""
Get the list of tenants (Xero Organisations) to which this token grants access.

Optionally, you may pass a UUID as auth_event_id that will be used to limit to
only those tenants that were authorised in that authorisation event.
"""
connection_url = self.base_url + XERO_OAUTH2_CONNECTIONS_URL

if auth_event_id:
connection_url += '?authEventId=' + auth_event_id

response = requests.get(connection_url, auth=self.oauth, headers=self.headers)
if response.status_code == 200:
return response.json()
Expand Down