Utilities for working with O365 Outlook and OAuth2
Many thanks to Chilkat Software, their Perl library and examples saved me uncountable hours on this project.
To use o365-token-saver.pl:
- Create an application in your AAD environment, and note the client ID and Client secret. (If you're not sure what this is, there is a walkthrough)
- TODO: There are some extra AAD steps here, like setting the callback URL and API permissions, that need to be added here
- Install Perl (On Windows, use Strawberry Perl)
- Install the Chilkat library
- Create a directory to work in, and download o365-token-saver.pl to it
- Alter the code to include your Chilkat license key
- Create a
.o365
directory under the work directory - Create the file
_nn_-config.json
in the.o365
directory based on the00-config.json
file in this repo - Replace all of the placeholders in that file with the appropirate values from your environment
- IMPORTANT: If there is a firewall on the system where you are running this script, configure it to allow requests to TCP/3017 to reach
o365-token-saver.pl
or it won't work - Run
o365-token-saver.pl
with the_nn_
from step 7 as the only command-line parameter - When the browser opens, enter the email address and password
- If this is the first time using this account with this application, you will also need to grant the application the requested permissions
- If you complete the sign-on within 30 seconds, the browser will display a success message
- The access token has been saved as
_nn_-token.json
in the .o365 directory
The remaining instructions are application specific and won't make much sense without that application.
To use img-eng-email.pl.patch.o365:
On a system with a recent version of /usr/bin/img-eng-email.pl, use the command patch -p0 < img-eng-email.pl.patch.o365
to alter it to invoke img-eng-email-o365.pl for message download when cnf_Email_Import.cei_Options
contains the 365
flag.
To use img-eng-email-o365.pl:
- Place it in the
/var/imaging/bin/
directory with appropriate ownereship and permission - Don't forget to update it to include your license key
- Install the Chilkat Perl library that matches this version of Perl
- Create the
/home/mailer/.o365
directory, with RWX permissions for the imaging group - Place the
_nn_-config.json
file used witho365-token-saver.pl
in the directory created in step 2 - Place the
_nn_-token.json
file generated byo365-token-saver.pl
in the directory created in step 2 psql images -c "UPDATE cnf_Email_Import SET cei_Options = cei_Options || ' 365' WHERE cei_Sequence = _nn_;"
- Optional:
su mailer
and run it manually with/var/imaging/bin/img-eng-email-o365.pl _nn_
- Check
/var/log/imaging/mailer
to see if it is working