Reputation: 67
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!
Upvotes: 2
Views: 3912
Reputation: 103
This could help if anyone still faces the problem you can set the Redirect Url manually
$driver = Socialite::driver('google');
$driver->redirectUrl('your-custom-url');
Upvotes: 0
Reputation: 26477
I use the following service provider in order to automatically fill in the redirect
for each provider where it's empty.
It could be modified to update your configuration on the fly. It depends exactly what you're trying to do I suppose.
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class SocialServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
collect(config('services'))
->only(config('social.providers'))
->reject(function($config) {
return array_get($config, 'redirect', false);
})
->each(function($config, $key) {
$url = url("login/{$key}/callback", [], true);
config(["services.{$key}.redirect" => $url]);
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
}
Upvotes: 0
Reputation: 1181
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
Upvotes: 8