Skip to content

Commit 79f9947

Browse files
committed
odata serialization optimizations & app-only access token error handling enhancements
1 parent 26049e1 commit 79f9947

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

office365/runtime/auth/providers/acs_token_provider.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ def get_app_only_access_token(self):
4242
url_info = urlparse(self.url)
4343
return self._get_app_only_access_token(url_info.hostname, realm)
4444
except requests.exceptions.RequestException as e:
45-
self.error = e.response.text if e.response else None
45+
self.error = e.response.text if e.response is not None else "Acquire app-only access token failed."
4646
raise ValueError(self.error)
4747

4848
def _get_app_only_access_token(self, target_host, target_realm):
4949
"""
50+
Retrieves an app-only access token from ACS to call the specified principal
51+
at the specified targetHost. The targetHost must be registered for target principal.
5052
51-
:type target_host: str
52-
:type target_realm: str
53+
:param str target_host: Url authority of the target principal
54+
:param str target_realm: Realm to use for the access token's nameid and audience
5355
"""
5456
resource = self.get_formatted_principal(self.SharePointPrincipal, target_host, target_realm)
5557
principal_id = self.get_formatted_principal(self._client_id, None, target_realm)
@@ -67,11 +69,15 @@ def _get_app_only_access_token(self, target_host, target_realm):
6769
return TokenResponse.from_json(response.json())
6870

6971
def _get_realm_from_target_url(self):
72+
"""Get the realm for the URL"""
7073
response = requests.head(url=self.url, headers={'Authorization': 'Bearer'})
7174
return self.process_realm_response(response)
7275

7376
@staticmethod
7477
def process_realm_response(response):
78+
"""
79+
:type response: requests.Response
80+
"""
7581
header_key = "WWW-Authenticate"
7682
if header_key in response.headers:
7783
auth_values = response.headers[header_key].split(",")

office365/runtime/odata/request.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from office365.runtime.http.http_method import HttpMethod
88
from office365.runtime.http.request_options import RequestOptions
99
from office365.runtime.odata.v3.json_light_format import JsonLightFormat
10-
from office365.runtime.paths.service_operation import ServiceOperationPath
1110
from office365.runtime.queries.create_entity import CreateEntityQuery
1211
from office365.runtime.queries.delete_entity import DeleteEntityQuery
1312
from office365.runtime.queries.service_operation import ServiceOperationQuery
@@ -65,8 +64,6 @@ def process_response(self, response, query):
6564
if isinstance(json_format, JsonLightFormat):
6665
if isinstance(query, ServiceOperationQuery):
6766
json_format.function = query.method_name
68-
elif isinstance(return_type.resource_path, ServiceOperationPath):
69-
json_format.function = return_type.resource_path.name
7067

7168
self.map_json(response.json(), return_type, json_format)
7269

tests/sharepoint/test_web.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ def test_25_parse_datetime(self):
148148
result = self.client.web.parse_datetime(today).execute_query()
149149
self.assertIsNotNone(result.value)
150150

151-
def test_26_list_acs_service_principals(self):
152-
result = self.client.web.get_acs_service_principals().execute_query()
153-
self.assertIsNotNone(result.value)
151+
#def test_26_list_acs_service_principals(self):
152+
# result = self.client.web.get_acs_service_principals().execute_query()
153+
# self.assertIsNotNone(result.value)
154154

155155
def test_27_ensure_tenant_app_catalog(self):
156156
result = self.client.web.ensure_tenant_app_catalog("app").execute_query()

0 commit comments

Comments
 (0)