Search code examples
phplaraveloauthoauth-2.0laravel-socialite

Dynamic Laravel Socialite Configurations


I need to configure my providers dynamically.

$config = [
    'client_id' = 'xxxxxxx',
    'client_token' = 'xxxxxxx',
    'redirect' = 'http://example.com/'
];
return Socialite::with($provider)->setConfig($config)->redirect();

But unfortunately there is no function setConfig.

I need to set provider, client_id, client_secret and redirect dynamically

Is there any ideas?

Thank you!


Solution

  • You could use the Socialite buildProvider method like:

    $config = [
        'client_id'    = 'xxxxxxx',
        'client_token' = 'xxxxxxx',
        'redirect'     = 'http://example.com/'
    ];
    
    return Socialite::buildProvider(\Laravel\Socialite\Two\FacebookProvider::class, $config);
    

    Where \Laravel\Socialite\Two\FacebookProvider::class would be swapped with your service (if different) as provided in either folder One/Two in https://github.com/laravel/socialite/tree/2.0/src