diff --git a/src/Features.php b/src/Features.php index 2961ec04..16db2f8f 100644 --- a/src/Features.php +++ b/src/Features.php @@ -15,6 +15,16 @@ public static function enabled(string $feature) return in_array($feature, config('socialstream.features', [])); } + /** + * Determine if the application has the generates missing emails feature enabled. + * + * @return bool + */ + public static function generatesMissingEmails() + { + return static::enabled(static::generateMissingEmails()); + } + /** * Determine if the application supports creating accounts * when logging in for the first time via a provider. @@ -46,6 +56,16 @@ public static function hasRememberSessionFeatures() return static::enabled(static::rememberSession()); } + /** + * Enabled the generate missing emails feature. + * + * @return string + */ + public static function generateMissingEmails() + { + 'generate-missing-emails'; + } + /** * Enable the create account on first login feature. * diff --git a/src/Http/Controllers/OAuthController.php b/src/Http/Controllers/OAuthController.php index 43a56e3b..06c41212 100644 --- a/src/Http/Controllers/OAuthController.php +++ b/src/Http/Controllers/OAuthController.php @@ -95,6 +95,11 @@ public function handleProviderCallback(Request $request, string $provider) try { $providerAccount = Socialite::driver($provider)->user(); + + if (Socialstream::generatesMissingEmails()) { + $providerAccount->email = $providerAccount->getEmail() ?? "{$providerAccount->id}@{$provider}".config('app.domain'); + } + } catch (InvalidStateException $e) { $this->invalidStateHandler->handle($e); } diff --git a/src/Socialstream.php b/src/Socialstream.php index 41f6717a..bca52f17 100644 --- a/src/Socialstream.php +++ b/src/Socialstream.php @@ -146,6 +146,16 @@ public static function hasTwitterSupport() return Providers::hasTwitterSupport(); } + /** + * Determine if the application has the generates missing emails feature enabled. + * + * @return bool + */ + public static function generatesMissingEmails() + { + return Features::generatesMissingEmails(); + } + /** * Determine if the application has the create account on first login feature. *