2016-10-12 120 views
0

我需要動態配置我的提供程序。動態Laravel社交網站配置

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

但不幸的是沒有函數setConfig。

我需要設置提供商,CLIENT_ID,client_secret和動態重定向

有什麼想法?

謝謝!

回答

0

你可以使用社交名媛buildProvider方法,如:

$config = [ 
    'client_id' = 'xxxxxxx', 
    'client_token' = 'xxxxxxx', 
    'redirect'  = 'http://example.com/' 
]; 

return Socialite::buildProvider(\Laravel\Socialite\Two\FacebookProvider::class, $config); 

\Laravel\Socialite\Two\FacebookProvider::class將與您的服務(如不同)調換爲任何文件夾中提供One/Twohttps://github.com/laravel/socialite/tree/2.0/src

+0

日Thnx,它的工作原理) –

+0

還有一,我不明白我怎麼能更改\ Laravel \社會名流\二\ FacebookProvider ::一流的服務,例如,如果我已經包括額外的Instagram提供商......莫非你解釋一下? –

+0

您可以使用以下包提供給Instagram提供商:) http://socialiteproviders.github.io/providers/instagram/ – Ryan

0

我用下面的服務提供商爲了自動填寫每個提供商爲空的供應商的redirect

它可以被修改以實時更新您的配置。這取決於你想要做什麼,我想。

<?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() 
    { 
    } 
}