Laravel Auth ::尝试不断失败

时间:2014-03-23 21:28:42

标签: oauth laravel laravel-4

我正在使用此代码通过Facebook和laravel-oauth2包对用户进行身份验证。但我的Auth :: atempt一直都在失败。(Ecos FLAG)有人可以帮我看看问题吗?这是我的控制器功能和我的路线代码:

Route::get('oauth/{provider}', 'HomeController@provide');

public function provide($provider)
{

       $init_p = $provider;

            $provider = OAuth2::provider($provider, array(
            'id' => 'MY ID',
            'secret' => 'MY SECRET',
        ));

    if ( ! isset($_GET['code']))
    {

        return $provider->authorize();
    }
    else
    {

        try
        {
            $params = $provider->access($_GET['code']);

                $token = new Token_Access(array(
                    'access_token' => $params->access_token
                ));
                $provided_user = $provider->get_user_info($token);


            if($init_p == 'facebook')
            {
                    if (User::whereFacebookUid($provided_user['uid'])->first())
                    {


                        if(Auth::check())
                        {
                            return Redirect::to('/testovi');
                        }
                        else
                        {


                            if (Auth::attempt(array('password' => $provided_user['uid'])))
                            {
                                return Redirect::to('/testovi');
                            }
                            else
                            {
                                echo("FLAG");
                            }
                        }

                    }
                    else
                    {
                        $user = new User;
                        $user->name = $provided_user['name'];
                        $user->email = $provided_user['email'];
                        $user->password = $provided_user['uid'];
                        $user->facebook_uid = $provided_user['uid'];
                        $user->save();

                        Auth::login($user);
                        return Redirect::to('testovi');

                    }



            }
        }

        catch (OAuth2_Exception $e)
        {
            show_error('That didnt work: '.$e);
        }
    }

}

1 个答案:

答案 0 :(得分:0)

解决方法是将HASH uid保存到db。详情来自:

Details

$user = new User;
$user->username = $provided_user['name'];
$user->email = $provided_user['email'];
$user->password = Hash::make($provided_user['uid']);
$user->facebook_uid = $provided_user['uid'];
$user->save();
Auth::login($user);
return Redirect::to('testovi');