2024-03-06 16:30:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use App\Models\OauthSetting;
|
|
|
|
use Laravel\Socialite\Facades\Socialite;
|
|
|
|
|
|
|
|
function get_socialite_provider(string $provider)
|
|
|
|
{
|
|
|
|
$oauth_setting = OauthSetting::firstWhere('provider', $provider);
|
2024-03-22 19:22:27 +00:00
|
|
|
|
|
|
|
if ($provider == 'azure') {
|
|
|
|
$azure_config = new \SocialiteProviders\Manager\Config(
|
|
|
|
$oauth_setting->client_id,
|
|
|
|
$oauth_setting->client_secret,
|
|
|
|
$oauth_setting->redirect_uri,
|
|
|
|
['tenant' => $oauth_setting->tenant],
|
2024-06-10 20:43:34 +00:00
|
|
|
);
|
|
|
|
|
2024-03-22 19:22:27 +00:00
|
|
|
return Socialite::driver('azure')->setConfig($azure_config);
|
|
|
|
}
|
|
|
|
|
2024-03-06 16:30:19 +00:00
|
|
|
$config = [
|
|
|
|
'client_id' => $oauth_setting->client_id,
|
|
|
|
'client_secret' => $oauth_setting->client_secret,
|
|
|
|
'redirect' => $oauth_setting->redirect_uri,
|
|
|
|
];
|
2024-03-22 19:22:27 +00:00
|
|
|
|
2024-03-06 16:30:19 +00:00
|
|
|
$provider_class_map = [
|
|
|
|
'bitbucket' => \Laravel\Socialite\Two\BitbucketProvider::class,
|
|
|
|
'github' => \Laravel\Socialite\Two\GithubProvider::class,
|
|
|
|
'gitlab' => \Laravel\Socialite\Two\GitlabProvider::class,
|
|
|
|
'google' => \Laravel\Socialite\Two\GoogleProvider::class,
|
|
|
|
];
|
2024-03-22 19:22:27 +00:00
|
|
|
|
2024-03-06 16:30:19 +00:00
|
|
|
return Socialite::buildProvider(
|
|
|
|
$provider_class_map[$provider],
|
|
|
|
$config
|
|
|
|
);
|
|
|
|
}
|