mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-17 00:55:07 +00:00
4eb8cf915a
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.
29 lines
850 B
PHP
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."),
|
|
};
|
|
}
|
|
}
|