nf / social
社交登录提供者
2.0.7
2018-05-04 06:34 UTC
Requires
- php: >=5.6
- laravel/socialite: ^3.0
README
这是我们主题 https://github.com/hieu-pv/nf-theme 的扩展
安装
步骤 1:通过 Composer 安装
composer require nf/social
步骤 2:添加服务提供者
打开
config/app.php并注册所需的服务提供者。
'providers' => [ // .... Others providers \NightFury\Social\SocialServiceProvider::class, ],
步骤 3:创建回调 URL
创建一个新页面,并使用短代码 [nf_social_oauth_callback],然后使用页面的 URL 作为回调 URL,并添加一个额外的查询参数 ?provider={your_provider}
例如,我们有一个 URL 为 https://{your_domain}/oauth 的页面,那么我们使用
https://{your_domain}/oauth?provider=facebook作为 Facebook 应用的回调 URLhttps://{your_domain}/oauth?provider=twitter作为 Twitter 应用的回调 URLhttps://{your_domain}/oauth?provider=google作为 Google 应用的回调 URL
步骤 4:更新配置文件 config/app.php 中的 CLIENT_ID 和 SECRET_KEY
<?php return [ // Other config 'services' => [ 'facebook' => [ 'client_id' => 'your_facebook_app_client_id', 'client_secret' => 'your_facebook_app_secret_key', 'redirect' => 'https://{your_domain}/oauth?provider=facebook', // use callback url from step 3 ], 'twitter' => [ 'client_id' => 'your_twitter_app_client_id', 'client_secret' => 'your_twitter_app_secret_key', 'redirect' => 'https://{your_domain}/oauth?provider=twitter', // use callback url from step 3 ], 'google' => [ 'client_id' => '', 'client_secret' => '', 'redirect' => '', ], ], ]
步骤 5:显示登录 URL
我们有一个短代码 [nf_social_url providers] 用于渲染登录 URL
[nf_social_url providers="facebook,twitter"]
您可以在任何需要显示登录按钮的地方使用它
或者您可以为每个提供者生成登录 URL
$facebook_login_url = \NightFury\Social\Facades\Social::driver('facebook')->stateless()->redirect()->getTargetUrl(); $google_login_url = \NightFury\Social\Facades\Social::driver('google')->stateless()->redirect()->getTargetUrl(); $twitter_login_url = \NightFury\Social\Facades\Social::driver('twitter')->redirect()->getTargetUrl();