@@ -286,7 +286,100 @@ $ sudo chown -R postfix:postfix /var/spool/postfix/etc/tokens
286
286
287
287
Skip to [ restart Postfix] ( #restart-postfix ) below.
288
288
289
- ### Outlook/Office 365 Configuration
289
+ ### Outlook/Office 365 Configuration (Device Flow)
290
+
291
+ This is the preferred method to authenticate with Outlook/Office, but the
292
+ [ fallback legacy client
293
+ approach] ( #outlookoffice-365-configuration-legacy-client-deprecated ) does still
294
+ work (... for now).
295
+
296
+ #### Client Credentials
297
+
298
+ Follow [ Microsoft's instructions to register an
299
+ application] ( https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app#register-an-application ) ,
300
+ with some notes:
301
+
302
+ * Use any name you like (it doesn't have to be "sasl-xoauth2").
303
+ * Do ** not** add any redirect URIs or set up any platform configurations.
304
+ * You ** must** toggle "Allow public client flows" to "yes".
305
+
306
+ Then, add API permissions for ` SMTP.Send ` :
307
+
308
+ 1 . From the app registration "API permissions" page, click "add a permission".
309
+ 1 . Click "Microsoft Graph".
310
+ 1 . Enter "SMTP.Send" in the search box.
311
+ 1 . Expand the ` SMTP ` permission, then check the ` SMTP.Send ` checkbox.
312
+
313
+ Store the "application (client) ID" (which you'll find in the "Overview" page
314
+ for the application you registered with Azure) in ` /etc/sasl-xoauth2.conf ` .
315
+ Leave ` client_secret ` blank. Additionally, explicitly set the token endpoint
316
+ (` sasl-xoauth2 ` points to Gmail's token endpoint by default):
317
+
318
+ ``` json
319
+ {
320
+ "client_id" : " client ID goes here" ,
321
+ "client_secret" : " " ,
322
+ "token_endpoint" : " https://login.microsoftonline.com/consumers/oauth2/v2.0/token"
323
+ }
324
+ ```
325
+
326
+ We'll also need these credentials in the next step.
327
+
328
+ #### A Note on Token Endpoints
329
+
330
+ The endpoint above
331
+ (` https://login.microsoftonline.com/consumers/oauth2/v2.0/token ` ) is suitable
332
+ for use with consumer Outlook accounts. For other types of accounts it may be
333
+ necessary to replace ` consumers ` with ` common ` , ` organizations ` , or a specific
334
+ tenant ID. See [ Microsoft's OAuth protocol
335
+ documentation] ( https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols#endpoints )
336
+ for more on this.
337
+
338
+ #### Initial Access Token
339
+
340
+ The sasl-xoauth2 package includes a script that can assist in the generation of
341
+ Microsoft OAuth tokens. Run the script as follows:
342
+
343
+ ``` shell
344
+ $ sasl-xoauth2-tool get-token outlook \
345
+ --client-id=CLIENT_ID_FROM_SASL_XOAUTH2_CONF \
346
+ --use-device-flow \
347
+ PATH_TO_TOKENS_FILE
348
+ To sign in, use a web browser to open the page https://www.microsoft.com/link and enter the code REDACTED to authenticate.
349
+ ```
350
+
351
+ If using a tenant other than ` consumers ` , pass ` --tenant=common ` ,
352
+ ` --tenant=organizations ` , or ` --tenant=TENANT_ID ` . The client ID will
353
+ be the same one written to ` /etc/sasl-xoauth2.conf ` . And ` PATH_TO_TOKENS_FILE `
354
+ will be the file specified in ` /etc/postfix/sasl_passwd ` . In our example that
355
+ file will be either
` /etc/tokens/[email protected] ` or
356
+ ` /var/spool/postfix/etc/tokens/[email protected] ` (see
[ A Note on
357
+ chroot] ( #a-note-on-chroot ) ).
358
+
359
+ Visit the link in a browser, enter the code, then accept the various prompts.
360
+ After authorizing the application, the tool will write a token to the path
361
+ specified.
362
+
363
+ ```
364
+ To sign in, use a web browser to open the page https://www.microsoft.com/link and enter the code REDACTED to authenticate.
365
+ Acquired token.
366
+ ```
367
+
368
+ It may be necessary to adjust permissions on the resulting token file so that
369
+ Postfix (or, more accurately, sasl-xoauth2 running as the Postfix user) can
370
+ update it:
371
+
372
+ ```
373
+ $ sudo chown -R postfix:postfix /etc/tokens
374
+ ```
375
+
376
+ or:
377
+
378
+ ```
379
+ $ sudo chown -R postfix:postfix /var/spool/postfix/etc/tokens
380
+ ```
381
+
382
+ ### Outlook/Office 365 Configuration (Legacy Client) (Deprecated)
290
383
291
384
#### Client Credentials
292
385
0 commit comments