Laravel Socialite请求返回Null

时间:2015-09-11 06:58:45

标签: php laravel laravel-5 laravel-socialite laravel-request

我正在使用Laravel Socialite 5.0。

<?php

use Illuminate\Http\Request;

public function login(AuthenticateUser $authenticateUser, Request $request){
    return $authenticateUser->execute($request->has('code'));
}

$request->has('code')始终返回null。这是为什么? 提供我的AuthenticateUser类,我将其视为重定向/请求问题。

<?php 

namespace App;

use Laravel\Socialite\Contracts\Factory as Socialite;
use Illuminate\Contracts\Auth\Guard as Guard;
use App\Repositories\UserRepository as UserRepository;
use Log;

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) {
        if( ! $hasCode){
            Log::info('1');
            return $this->getAuthorizationFirst();
        }
        Log::info('2');
        $user = $this->socialite->driver('github')->user();
    }

    public function getAuthorizationFirst(){
        return $this->socialite->driver('github')->redirect();
    }

}

添加AuthController类以供参考:

class AuthController extends Controller {

    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers;

    /**
     * Create a new authentication controller instance.
     *
     * @param  \Illuminate\Contracts\Auth\Guard  $auth
     * @param  \Illuminate\Contracts\Auth\Registrar  $registrar
     * @return void
     */
    public function __construct(Guard $auth, Registrar $registrar)
    {
        $this->auth = $auth;
        $this->registrar = $registrar;

        $this->middleware('guest', ['except' => 'getLogout']);
    }

    public function login(AuthenticateUser $authenticateUser, Request $request){
        Log::info('_'.$request->has('code').'_');
        return $authenticateUser->execute($request->has('code'));
    }

}

1 个答案:

答案 0 :(得分:0)

问题出在返回网址上! 我从应用程序返回错误的路线。