TheNetworg/oauth2-azure

phpmailer token

yanndupont opened this issue · 3 comments

Hello is there someone making it works with the auth token and phpmailer?

I tried to use the refrehed token but phpmailer return CLIENT: 535 5.7.3 Authentication unsuccessful
Using graph api is great but i struggle with phpmailer.

$mail->setOAuth(
new OAuth(
[
'provider' => $provider,
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'refreshToken' => $refreshToken,
'userName' => $email,
]
)
);

i also tried to set url of the api and version without more success
$provider->urlAPI = 'https://graph.microsoft.com/';
$provider->API_VERSION = '1.0';

Any help is welcome,
Thanks

The two usual reasons for authentication failure are bad token and wrong scope:

  • the token you are giving to PHPMailer as a refresh token isn't a refresh token (perhaps it is an authentication token)
  • the scope you are specifying gives an AUD claim of Graph: see "Microsoft OAuth2 SMTP issues" in the PHPMailer WiKi

Hi

The two usual reasons for authentication failure are bad token and wrong scope:

  • the token you are giving to PHPMailer as a refresh token isn't a refresh token (perhaps it is an authentication token)
  • the scope you are specifying gives an AUD claim of Graph: see "Microsoft OAuth2 SMTP issues" in the PHPMailer WiKi

Hi,
i use the scope https://outlook.office.com/SMTP.Send when calling the provider
'scopes' => ['openid profile email offline_access https://outlook.office.com/SMTP.Send']
the token is indeed an authentication one.
The goal is to call one time (and not twice) the url back to identify, grab user details and use smtp.

If you decode the access token with e.g. jwt.ms (you might need to debase64 decode the token first using https://www.base64decode.org/ ), please let us have the AUD claim. To see the access token, enable SMTP debugging using (in your PHPMailer script) $this->mail->SMTPDebug = SMTP::DEBUG_LOWLEVEL; It will be displayed as a long character string just before your authentication fails,

Note that you cannot decode a refresh token