公式の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 認証に変更してみました。ビデオの(具体的には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) が何も返さないため、機能していない/変換していない部分です..