Files
projectsend/app/Modules/Platform/Mail/MailOAuthBrokers.php
denkfabrik-li 4eb8cf915a Add Google / Gmail as the second OAuth mail provider
Same delegated shape as the Microsoft 365 provider, through the same
broker interface: the admin registers an OAuth client in Google Cloud
Console, connects the Google account the installation should send as,
and outgoing email goes through the Gmail API's messages.send as that
account.

The shared authorization-code machinery (exchange, refresh, token
storage, id_token account detection, RFC 6749 failure telling a dead
grant from a transient one) moves into an abstract OAuthCodeFlowBroker;
the two vendor brokers keep only their endpoints, scopes and consent
URL parameters. Google's quirks live where they belong: offline access
with a forced consent screen (the only way Google issues a refresh
token), and a refresh response that never re-sends one — the store
keeps what it has.

The settings screen needed no changes: the dropdown, the credential
form and the connect flow all derive from the provider enum.
2026-08-23 22:46:24 +02:00

29 lines
850 B
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Platform\Mail;
use App\Modules\Platform\Settings\MailProvider;
use InvalidArgumentException;
/**
* Resolves the broker for an OAuth mail provider.
*
* A closed map rather than an open registry, for the same reason
* SocialProvider is a closed enum: each broker encodes decisions about a
* vendor's token semantics (rotation, what kills a grant) that somebody
* has reasoned about.
*/
class MailOAuthBrokers
{
public function for(MailProvider $provider): MailOAuthBroker
{
return match ($provider) {
MailProvider::Microsoft365 => app(MicrosoftMailBroker::class),
MailProvider::Gmail => app(GoogleMailBroker::class),
default => throw new InvalidArgumentException("{$provider->value} is not an OAuth mail provider."),
};
}
}