Laracast (Laravel 5.0 - Socialite)でこのチュートリアルを使用して、特に12.11 分まで、すべてを正常にセットアップしました。ただし、Laravel 5.1 を使用しています。
ルートを定義しましたが、取得したトークンを使用してユーザーの詳細を取得しようとしているだけなので、現在コールバック プロバイダーをコメントアウトしています。
Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider'); //Route::get('auth/facebook/aaa', 'Auth\AuthController@handleProviderCallback');
に追加された必需品
config>services.php
:'facebook' => [ 'client_id' => '##', 'client_secret' => env('FB_SECRET_ID'), 'redirect' => 'http://laratest.dev/auth/facebook', ],
とりあえず同じページ( )に戻ることにしましたauth/facebook
。domain.devv/auth/facebook
そのため、テスト用としてリターンを設定しました。
私の
AuthController.php
では、次のように設定しました。public function redirectToProvider(AuthenticateUser $authenticateUser, Request $request) { return $authenticateUser->execute($request->has('code')); }
そして最後に、私の中で
AuthenticateUser.php
: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(); } }
今、私はLogin with Facebook
リンクをクリックしてリダイレクトされますdomain.dev/auth/facebook?code=943299043290...
のみを使用すると*First dd
(他のすべてのコメント行がコメント化されている場合)、 が返されますfalse
。
*Second dd
(行にコメントを付けて)のみを使用すると$user = $this->socialite->driver('facebook')->user();
、 が返されますtrue
。
したがって、すべてが完璧に機能し、 を通過しexecute()
、次に を通過しgetAuthorizationFirst()
ます。最後に、取得したトークンを使用して に戻ります。execute()
このトークンもリンクに含まれています ( domain.dev/auth/facebook?code=943299043290...
)。
私の問題はここで発生します:
2 番目にコメントを解除$user = $this->socialite->driver('facebook')->user();
すると、エラーが発生します。
Middleware.php 行 69 の ClientException: クライアント エラー: 400
1. /Applications/MAMP/htdocs/laratest/vendor/guzzlehttp/guzzle/src/Middleware.php 69 行目
2. at Middleware::GuzzleHttp{closure}(object(Response)) Promise.php 行 199
3. at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) Promise.php 行 152
4. TaskQueue.php 60 行目の Promise::GuzzleHttp\Promise{closure}() で
5. CurlMultiHandler.php 行 96 の TaskQueue->run()
この行($user = $this->socialite->driver('facebook')->user();
)は、何らかの理由で機能しません(チュートリアルでは機能しますが(15秒の簡単な説明の場合は最小12.11))。
を使用するたびに$user = $this->socialite->driver('facebook')->user();
エラーが発生ClientException in Middleware.php line 69: Client error: 400
し、もちろん取得できませんdd($user)
。
追加するには、ClientException エラーが表示されても、リンクにはまだコードがあります: ( domain.dev/auth/facebook?code=943299043290...
)