https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/tokenhttps://outlook.office.com/SMTP.Send offline_access6.2
Joomla exchanges the authorization code and stores the refresh token.
After the redirect back to Joomla:
Error code 404 received requesting access token: Not Found..
The configuration is correct (tenant ID verified, authorization works). The problem is in the HTTP request itself. I tested the token endpoint from the same server with plain PHP:
| Request | Result |
|---|---|
| cURL default (TLS 1.3 + ALPN) | 404 |
cURL with CURLOPT_SSL_ENABLE_ALPN => false |
OK (400 AADSTS900144 as expected for a dummy request) |
| cURL limited to TLS 1.2 | OK |
| PHP stream wrapper (no cURL) | OK |
| Same URL in a browser | OK |
/.well-known/openid-configurationSo with this cURL/OpenSSL combination, Microsoft's login endpoint answers 404 whenever ALPN is offered over TLS 1.3. As OpenSSL 3.5 becomes more common on hosting servers, other sites will likely run into this.
Workaround (confirmed working, token received and test mail delivered): add the cURL option to both OAuth2 clients:
administrator/components/com_config/src/Controller/MailController.php → createOAuth2Client()libraries/src/Mail/MailOAuth2TokenProvider.php → requestAccessToken()'transport.curl' => [\CURLOPT_SSL_ENABLE_ALPN => false],Suggestion: Since the token requests only need HTTP/1.1, disabling ALPN for these two requests (or retrying without ALPN on failure) should be safe and would make the feature work on affected servers without core hacks.
| Labels |
Added:
bug
|
||
| Labels |
Added:
No Code Attached Yet
|
||
Hi,
thanks for looking into it! Sorry, I should have been clearer: the redirect itself works fine.
The failing step is the server-side token exchange that happens right after the redirect: Joomla receives the code and then calls $oauth2->authenticate() in MailController::oauth2callback(), which sends a POST request from the web server to the Microsoft token endpoint using the cURL transport of joomla/http. This request gets an HTTP 404 from Microsoft.
The same applies later to MailOAuth2TokenProvider::requestAccessToken(), which refreshes the access token via cURL whenever a mail is sent.
It can be reproduced without Joomla on the affected server (PHP 8.4.26, cURL 8.14.1, OpenSSL 3.5.7):
$url = 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration';
// 1) cURL defaults (TLS 1.3 + ALPN) -> 404
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), PHP_EOL; // 404
// 2) Same request with ALPN disabled -> 200
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_ENABLE_ALPN, false);
curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), PHP_EOL; // 200Some additional information that may help to assess the impact:
Hosting provider: IONOS (web hosting package)
HTTP(S)_PROXY / ALL_PROXY not set)As IONOS is one of the largest hosting providers in Germany and Europe, I assume that a considerable number of Joomla sites could run into this as soon as they try the new SMTP OAuth2 feature with Microsoft 365.
Further findings from my tests on this server:
login.microsoftonline.com fails with 404 NotFound when ALPN is offered over TLS 1.3. This includes the public /.well-known/openid-configuration endpoint, not only the token endpoint.stamp2.login.microsoftonline.com, issued by DigiCert), so there is no TLS interception.stream_socket_client) to the same endpoint returns 200 OK with the usual Microsoft headers (x-ms-request-id, x-ms-ests-server).| Variant | Result |
|---|---|
| cURL default (TLS 1.3 + ALPN) | 404 |
cURL, CURLOPT_SSL_ENABLE_ALPN => false |
OK |
| cURL, max. TLS 1.2 | OK |
| PHP stream wrapper | OK |
Impact for users: Without a fix, the feature fails at the token exchange with only Error code 404 received requesting access token: Not Found... Nothing is written to the Joomla log, so it is very hard for site owners to find the cause. They will probably assume a misconfiguration in Microsoft Entra.
As this most likely affects several hosting providers with a similar cURL/OpenSSL stack, I think it should be solved in Joomla core rather than per hoster. Disabling ALPN for the two OAuth2 token requests would make the feature work on such servers. The workaround from my first post has been running in production without problems since then.
On question, is this shared hosting or a server with Debian?
One question, is this shared hosting or a server with Debian?
It's IONOS shared hosting (no root access), but I have SSH access and could check the system. PHP's php_uname() is masked by the hoster, the real values are:
8.14.1-2+deb13u5So this is not a custom build of the hoster, but the stock Debian 13 stack.
I could also reproduce the problem with the plain command line cURL, without PHP and without Joomla:
URL=https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration
curl -s -o /dev/null -w "Default: %{http_code}\n" $URL
curl -s -o /dev/null -w "No ALPN: %{http_code}\n" --no-alpn $URL
curl -s -o /dev/null -w "TLS 1.2: %{http_code}\n" --tls-max 1.2 $URLResult:
Default: 404
No ALPN: 200
TLS 1.2: 200
This means that any server running Debian 13 with the default packages is most likely affected, regardless of the hosting provider. As Debian 13 is the current stable release, the number of affected sites will grow as hosters upgrade.
Anyone with a Debian 13 system can verify this with the three commands above.
Interesting, I got another report of ionos unmanage debian trixie oauth authentication independent from the smtp thing.
On the other side I wrote the oauth implementation an debian trixie, I mean it's a custom compiled apache and php with bleeding edge curl version. So maybe it's a debian curl issue default setting.
But finally it's a Microsoft issue, at least that's my conclusion?! Anyway I'm discussing this with Maintainers.
thanks again for your help
Thanks a lot for looking into this and for discussing it with the maintainers!
I agree that the root cause is most likely on Microsoft's side (or in the interaction with the Debian curl/OpenSSL defaults). From a user's perspective, though, neither side can be changed: on shared hosting there is no way to modify curl, and Microsoft probably won't react quickly.
So a small workaround in core (disabling ALPN for the two token requests) would still be very helpful, especially as more hosters move to Debian 13. I'm happy to test a PR on an affected IONOS server.
I will create PR to disable alpn, not sure yet if for all connections or only Microsoft...
Hi,
thanks for the information, I'm not sure where the problem really sits. The redirect from microsoft to your page should not affect any curl implementation. since the browser does the redirect.
Maybe I missed something.