Skip to content

boolw/renrensocialite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

renrensocialite

open.renren.com OAuth2 Provider for Laravel Socialite

人人网认证(Renren)
使用如下Composer命令安装依赖:
composer require boolw/renrensocialite

注册服务提供者(同时注释掉原有的Socialite提供者):

//Laravel\Socialite\SocialiteServiceProvider::class,
SocialiteProviders\Manager\ServiceProvider::class,

添加Socialite门面(如果已有略过本操作):

'Socialite' => Laravel\Socialite\Facades\Socialite::class,

添加事件监听器(App/Providers/EventServiceProvider):

protected $listen = [
    'SocialiteProviders\Manager\SocialiteWasCalled' => [
        'Boolw\RenrenSocialite\RenrenExtendSocialite@handle',
    ],
];

去新浪微博开放平台(https://openapi.baidu.com/)创建一个新的网站应用以获取相应的App Key和App Secret。需要注意的是不比GitHub,新浪微博需要创建的网站应用对应网站在外网可以访问。

然后在配置文件app/services.php中添加renren配置项:

'renren' => [
    'client_id' => 'your renren app App Key',
    'client_secret' => 'your renren app App Secret',
    'redirect' => 'http://laravel.app:8000/auth/renren/callback'
]

接下来我们要对AuthController略作修改:

public function redirectToProvider(Request $request,$service)
{
    return Socialite::driver($service)->redirect();
}

public function handleProviderCallback(Request $request,$service)
{
    $user = Socialite::driver($service)->user();
    dd($user);
}

以支持多种不同认证提供者的切换。

最后需要修改认证路由规则如下:

Route::get('auth/{service}', 'Auth\AuthController@redirectToProvider');
Route::get('auth/{service}/callback', 'Auth\AuthController@handleProviderCallback');

至此就可以在浏览器中访问http://laravel.app:8000/auth/renren进行测试了。

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages