Microsoft Authentication Library (MSAL) plugin
This plugin is a wrapper for the Microsoft Authentication Library (MSAL) for Go library. It supports fetching OAuth2 access tokens for users in Office 365.
Configuration
For the configuration schema, see msal.schema.json. Below is a sample configuration.
smtpd.yaml
plugins:
- id: msal
path: /opt/halon/plugins/msal.so
config:
tenants:
- id: tenant1
client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
authority: https://login.microsoftonline.com/organizations
scopes:
- https://outlook.office.com/SMTP.Send
cache_file: /tmp/msal_tenant1_cache.json
Exported functions
msal(options)
Fetch an OAuth2 access token using the provided credentials. A successful fetch will return an associative array with a result
key that contains the access token. On error an associative array with a error
key will be provided.
Example
Below is an example on how to send email through Office 365 using OAuth2.
predelivery.hsl
$tenant = "tenant1";
$username = "[email protected]";
$password = "xxxxxxxx";
$result = msal(["id" => $tenant, "username" => $username, "password" => $password]);
if (!$result["result"]) {
Queue([
"reason" => "Could not fetch access token",
"increment_retry" => false,
"delay" => 60
]);
}
$password = "user=".$username."\x01auth=Bearer ".$result["result"]."\x01\x01";
Try([
"server" => "smtp.office365.com",
"port" => 587,
"saslmechanism" => "XOAUTH2",
"saslpassword" => $password
]);