2016-10-12 124 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() 
    { 
    } 
}