Skip to content

Commit 0d5168b

Browse files
vvgrem@gmail.comvvgrem@gmail.com
authored andcommitted
GraphClient: support for generic auth provider (adal, msal are supported), 3.5 excluded from Travis unittest build
1 parent 86e9715 commit 0d5168b

File tree

5 files changed

+31
-28
lines changed

5 files changed

+31
-28
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: python
22
os: linux
33
python:
4-
- '3.5'
54
- '3.6'
65
- '3.7'
76
- '3.8'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import msal
2+
3+
from settings import settings
4+
from office365.graph_client import GraphClient
5+
6+
7+
def acquire_token_msal():
8+
"""
9+
Acquire token via MSAL
10+
11+
"""
12+
authority_url = 'https://login.microsoftonline.com/{0}'.format(settings['tenant'])
13+
app = msal.ConfidentialClientApplication(
14+
authority=authority_url,
15+
client_id=settings['client_credentials']['client_id'],
16+
client_credential=settings['client_credentials']['client_secret']
17+
)
18+
result = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])
19+
return result
20+
21+
22+
client = GraphClient(settings['tenant'], acquire_token_msal)
23+
teams = client.teams.get_all().execute_query()
24+
for team in teams:
25+
print(team.id)

examples/teams/list_teams.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

office365/graph_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from office365.onedrive.sharedDriveItemCollection import SharedDriveItemCollection
1212
from office365.onedrive.siteCollection import SiteCollection
1313
from office365.outlookservices.contact_collection import ContactCollection
14+
from office365.runtime.auth.token_response import TokenResponse
1415
from office365.runtime.client_runtime_context import ClientRuntimeContext
1516
from office365.runtime.http.http_method import HttpMethod
1617
from office365.runtime.http.request_options import RequestOptions
@@ -68,10 +69,9 @@ def authenticate_request(self, request):
6869
6970
:type request: RequestOptions
7071
"""
71-
# authority_url = self._authority_host_url + '/' + self._tenant
72-
# auth_ctx = adal.AuthenticationContext(authority_url)
73-
token = self._acquire_token_callback()
74-
request.set_header('Authorization', 'Bearer {0}'.format(token["accessToken"]))
72+
token_json = self._acquire_token_callback()
73+
token = TokenResponse.from_json(token_json)
74+
request.set_header('Authorization', 'Bearer {0}'.format(token.accessToken))
7575

7676
def execute_request(self, url_or_options):
7777
"""

office365/runtime/auth/token_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ def _normalize_key(name):
2020
return key_parts[0] + "".join(names)
2121
return name
2222

23-
token_json = {_normalize_key(k): v for k, v in value.items()}
24-
return TokenResponse(**token_json)
23+
json = {_normalize_key(k): v for k, v in value.items()}
24+
return TokenResponse(**json)

0 commit comments

Comments
 (0)