Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel使用artdarek/oauth-4-Laravel进行谷歌身份验证_Php_Laravel 4_Google Oauth - Fatal编程技术网

Php Laravel使用artdarek/oauth-4-Laravel进行谷歌身份验证

Php Laravel使用artdarek/oauth-4-Laravel进行谷歌身份验证,php,laravel-4,google-oauth,Php,Laravel 4,Google Oauth,我正在使用Artdarek软件包使用google帐户登录,需要授权该应用程序的用户。 我用的是Laravel4.2 这是我函数中的代码 public function loginWithGoogle() { // get data from input $code = Input::get( 'code' ); // get google service $googleService = OAuth::consumer( 'Google' );

我正在使用Artdarek软件包使用google帐户登录,需要授权该应用程序的用户。 我用的是Laravel4.2

这是我函数中的代码

public function loginWithGoogle() {
        // get data from input
    $code = Input::get( 'code' );

    // get google service
    $googleService = OAuth::consumer( 'Google' );

    // check if code is valid

    // if code is provided get user data and sign in
    if ( !empty( $code ) ) {

        // This was a callback request from google, get the token
        $token = $googleService->requestAccessToken( $code );

        // Send a request with it
        $result = json_decode( $googleService->request( 'https://www.googleapis.com/oauth2/v1/userinfo' ), true );

        // Check to see if user already exists
        if($user = User::where('email', '=', $result['email'])->first())
        {
            $user = User::find($user['id']);
            Auth::login($user);
            // If user isn't activated redirect them
            if ($user->deactivated == 0)
            {
                return View::make('dashboard')->with('user', $user);
            }
                return Redirect::back()->withErrors(['Sorry You have not been approved', 'Speak to your manager']);
        }
        else
        {
            // Create new user waiting for approval
            $new_user = new User();
            $new_user->email = $result['email'];
            $new_user->first_name = $result['given_name'];
            $new_user->surname = $result['family_name'];
            $new_user->googleID = $result['id'];
            $new_user->deactivated = 1;
            $new_user->save();
            return Redirect::back()->withErrors(['Your account have been created. It is awaiting activation by your manager']);
        }


    }
    // if not ask for permission first
    else {
        // get googleService authorization
        $url = $googleService->getAuthorizationUri();

        // return to google login url
        return Redirect::to( (string)$url );
    }
}
当新用户授予应用程序权限时,我收到错误“无法重定向到空URL”


由于某些原因,我的
重定向url
是空的。

查看文档,您将发现必须在OAuth::consumer方法的第二个参数处设置重定向url

这意味着,您应该使用带有2个参数的consumer,而不是1个参数

$googleService = OAuth::consumer("google","https://mydirectlink");