【发布时间】:2015-07-23 12:17:41
【问题描述】:
使用官方Laravel Docs 5.1 - Socialite,我设置了路由并编辑了我的AuthController。
public function redirectToProvider()
{
return Socialite::driver('facebook')
->scopes(['public_profile', 'email'])->redirect();
}
完美运行并返回
http://domain.dev/auth/facebook/callback?code=AQDLFlYr...
然后我使用了Laracasts' Socialite - Laravel 5.0,我尝试将我的一个变成正确的 Facebook 身份验证。我在视频中做了所有事情,直到(min. 12.11,具体而言)。 (在 12.11 他在 15 秒内回顾了这些内容)。这就是我想要做的。
现在,当我将 AuthController 更改为:
public function redirectToProvider(AuthenticateUser $authenticateUser, Request $request)
{
return $authenticateUser->execute($request->has('code'));
}
...让我的AuthenticateUser class 像这样:
use Illuminate\Contracts\Auth\Guard; (PS. I changed Authenticator to Guard)
class AuthenticateUser {
private $users;
private $socialite;
private $auth;
public function __construct(UserRepository $users, Socialite $socialite, Guard $auth)
{
$this->users = $users;
$this->socialite = $socialite;
$this->auth = $auth;
}
public function execute($hasCode)
{
// dd($hasCode) *First dd
if ( ! $hasCode) return $this->getAuthorizationFirst();
$user = $this->socialite->driver('facebook')->user();
// dd($hasCode) *Second dd
// dd($user) *Third dd
}
private function getAuthorizationFirst()
{
return $this->socialite->driver('facebook')
->scopes(['public_profile', 'email'])->redirect();
}
}
*UserRepository is currently empty.
当我使用*First dd 时,我会在屏幕上收到False。
当我使用*Second dd 时,我收到True。
当我使用*Third dd 时,我什么也没收到。
现在,在所有这些情况下,我都收到了http://domain.dev/auth/facebook?code=9329409329042。
编辑:
我添加了
return,现在链接包括?code=9390249032...,但是当我使用*Third dd-dd($user)时,仍然没有返回任何内容-
我设法来到这里:
public function execute($hasCode) { dd($hasCode); // returns FALSE now if ( ! $hasCode) return $this->getAuthorizationFirst(); dd($hasCode); // returns TRUE now $user = $this->socialite->driver('facebook')->user(); dd($user); // BUT STILL RETURNS NOTHING }
.. 链接包括?code=9943290...
基本上,
$user = $this->socialite->driver('facebook')->user();是不工作/转换的部分,因为 dd($user) 没有返回任何内容..
【问题讨论】:
标签: facebook facebook-graph-api laravel laravel-socialite