@@ -112,13 +112,15 @@ the following clients are available:
112
112
113
113
#### Authentication
114
114
115
- In terms of Microsoft Graph API authentication, there is no any dependency to any particular library implementation,
116
- the following libraries are supported at least:
115
+ [ The Microsoft Authentication Library (MSAL) for Python] ( https://pypi.org/project/msal/ ) which comes as a dependency
116
+ is used as a default library to obtain token to call Microsoft Graph API. But in terms of Microsoft Graph API
117
+ authentication, another Microsoft Authentication Client compliant libraries such [ adal] ( https://github.com/AzureAD/azure-activedirectory-library-for-python )
118
+ as are supported as well.
117
119
118
120
> Note: access token is getting acquired via [ Client Credential flow] ( https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow )
119
121
> in the provided examples
120
122
121
- [ Microsoft Authentication Library (MSAL) for Python] ( https://pypi.org/project/msal/ )
123
+ Using [ Microsoft Authentication Library (MSAL) for Python] ( https://pypi.org/project/msal/ )
122
124
123
125
``` python
124
126
import msal
@@ -134,24 +136,24 @@ def acquire_token():
134
136
client_id = ' {client_id} ' ,
135
137
client_credential = ' {client_secret} '
136
138
)
137
- result = app.acquire_token_for_client(scopes = [" https://graph.microsoft.com/.default" ])
138
- return result
139
+ token = app.acquire_token_for_client(scopes = [" https://graph.microsoft.com/.default" ])
140
+ return token
139
141
140
142
141
143
client = GraphClient(acquire_token)
142
144
143
145
```
144
146
145
147
146
- [ ADAL Python] ( https://adal-python.readthedocs.io/en/latest/# )
148
+ Using [ ADAL Python] ( https://adal-python.readthedocs.io/en/latest/# )
147
149
148
150
Usage
149
151
150
152
``` python
151
153
import adal
152
154
from office365.graph_client import GraphClient
153
155
154
- def get_token ():
156
+ def acquire_token ():
155
157
authority_url = ' https://login.microsoftonline.com/{tenant_id_or_name} '
156
158
auth_ctx = adal.AuthenticationContext(authority_url)
157
159
token = auth_ctx.acquire_token_with_client_credentials(
@@ -160,7 +162,7 @@ def get_token():
160
162
" {client_secret} " )
161
163
return token
162
164
163
- client = GraphClient(get_token )
165
+ client = GraphClient(acquire_token )
164
166
165
167
```
166
168
@@ -171,19 +173,9 @@ The example demonstrates how to send an email via [Microsoft Graph endpoint](htt
171
173
> Note: access token is getting acquired via [ Client Credential flow] ( https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow )
172
174
173
175
``` python
174
- import adal
175
176
from office365.graph_client import GraphClient
176
177
177
- def get_token ():
178
- authority_url = ' https://login.microsoftonline.com/{tenant_id_or_name} '
179
- auth_ctx = adal.AuthenticationContext(authority_url)
180
- token = auth_ctx.acquire_token_with_client_credentials(
181
- " https://graph.microsoft.com" ,
182
- " {client_id} " ,
183
- " {client_secret} " )
184
- return token
185
-
186
- client = GraphClient(get_token)
178
+ client = GraphClient(acquire_token)
187
179
188
180
message_json = {
189
181
" Message" : {
@@ -217,8 +209,26 @@ client.execute_query()
217
209
218
210
#### Authentication
219
211
220
- [ ADAL Python] ( https://adal-python.readthedocs.io/en/latest/# )
221
- library is utilized to authenticate users to Active Directory (AD) and obtain tokens
212
+ [ The Microsoft Authentication Library (MSAL) for Python] ( https://pypi.org/project/msal/ ) which comes as a dependency
213
+ is used to obtain token
214
+
215
+ ``` python
216
+ import msal
217
+
218
+ def acquire_token ():
219
+ """
220
+ Acquire token via MSAL
221
+ """
222
+ authority_url = ' https://login.microsoftonline.com/{tenant_id_or_name} '
223
+ app = msal.ConfidentialClientApplication(
224
+ authority = authority_url,
225
+ client_id = ' {client_id} ' ,
226
+ client_credential = ' {client_secret} '
227
+ )
228
+ token = app.acquire_token_for_client(scopes = [" https://graph.microsoft.com/.default" ])
229
+ return token
230
+ ```
231
+
222
232
223
233
#### Examples
224
234
@@ -231,17 +241,9 @@ which corresponds to [`list available drives` endpoint](https://docs.microsoft.c
231
241
232
242
``` python
233
243
from office365.graph_client import GraphClient
234
- def get_token (auth_ctx ):
235
- """ Acquire token via client credential flow (ADAL Python library is utilized)"""
236
- token = auth_ctx.acquire_token_with_client_credentials(
237
- " https://graph.microsoft.com" ,
238
- " {client_id} " ,
239
- " {client_secret} " )
240
- return token
241
-
242
244
243
245
tenant_name = " contoso.onmicrosoft.com"
244
- client = GraphClient(get_token )
246
+ client = GraphClient(acquire_token )
245
247
drives = client.drives
246
248
client.load(drives)
247
249
client.execute_query()
@@ -254,7 +256,7 @@ for drive in drives:
254
256
255
257
``` python
256
258
from office365.graph_client import GraphClient
257
- client = GraphClient(get_token )
259
+ client = GraphClient(acquire_token )
258
260
# retrieve drive properties
259
261
drive = client.users[" {user_id_or_principal_name} " ].drive
260
262
client.load(drive)
@@ -288,8 +290,8 @@ Refer [OneDrive examples section](examples/onedrive) for a more examples.
288
290
289
291
#### Authentication
290
292
291
- [ ADAL Python] ( https://adal-python.readthedocs.io/en/latest/# )
292
- library is utilized to authenticate users to Active Directory (AD) and obtain tokens
293
+ [ The Microsoft Authentication Library (MSAL) for Python] ( https://pypi.org/project/msal/ ) which comes as a dependency
294
+ is used to obtain token
293
295
294
296
#### Examples
295
297
@@ -301,30 +303,16 @@ which corresponds to [`Create team` endpoint](https://docs.microsoft.com/en-us/g
301
303
``` python
302
304
from office365.graph_client import GraphClient
303
305
tenant_name = " contoso.onmicrosoft.com"
304
- client = GraphClient(tenant_name, get_token )
306
+ client = GraphClient(tenant_name, acquire_token )
305
307
new_team = client.groups[" {group_id} " ].add_team()
306
308
client.execute_query()
307
309
```
308
310
309
- where
310
-
311
- ``` python
312
- def get_token (auth_ctx ):
313
- """ Acquire token via client credential flow (ADAL Python library is utilized)
314
- :type auth_ctx: adal.AuthenticationContext
315
- """
316
- token = auth_ctx.acquire_token_with_client_credentials(
317
- " https://graph.microsoft.com" ,
318
- " {client_id} " ,
319
- " {client_secret} " )
320
- return token
321
- ```
322
-
323
311
324
312
# Third Party Libraries and Dependencies
325
313
The following libraries will be installed when you install the client library:
326
314
* [ requests] ( https://github.com/kennethreitz/requests )
327
- * [ adal ] ( https://github.com/AzureAD/azure-activedirectory-library-for-python )
315
+ * [ Microsoft Authentication Library (MSAL) for Python ] ( https://pypi.org/project/msal/ )
328
316
329
317
330
318
0 commit comments