将 hybrid_auth 整合到 laravel 5 中

Integration of hybrid_auth in laravel 5

我是 laravel 框架的新手,如有任何帮助,我们将不胜感激

当我尝试执行以下代码时出现此错误 FatalErrorException 在 SocialController.php 第 27 行:Class 'App\Http\Controllers\Hybrid_Auth' 在 SocialController.php 第 27 行找不到

当我从 SocialController.php 中删除名称空间时,我收到此错误提示 BaseController not found.

单击此按钮

 <a href="{{action("SocialController@getFacebookLogin")}}" class="submit-button btn btn-block btn-primary"><i class="fa fa-facebook"></i>&nbsp;&nbsp;Facebook</a>

SocialController.php

       <?php
        namespace App\Http\Controllers;
        use App\Http\Controllers\Controller; 
        use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

    class SocialController extends BaseController
    {


//this is the code for facebook Login
public function getFacebookLogin($auth=NULL)
{
    if ($auth == 'auth')
    {
        try
        {
            Hybrid_Endpoint::process();
        }
        catch (Exception $e)
        {
            return Redirect::to('fbauth');
        }
        return;
    }

    $oauth = new Hybrid_Auth(app_path(). '/config/fb_auth.php');
    $provider = $oauth->authenticate('Facebook');
    $profile = $provider->getUserProfile();
    return var_dump($profile).'<a href="logout">Log Out</a>';
}



   public function getLoggedOut()
{
    $fauth = new Hybrid_auth(app_path().'/config/fb_auth.php');
    $fauth->logoutAllProviders();
    return view::make('/');
}


 }

fb_auth.php

    <?php

   return array(
   "base_url" => "http://urmk.com/fbauth/auth",
   "providers" => array (
  "Facebook" => array (
  "enabled" => true,
  "keys"    => array ( "id" => "APP_ID", "secret" =>  "APP_SECRET" ),
  "scope"   => "email"
)
    )
     );

Routes.php

    Route::get('fbauth/{auth?}' ,array('as'=>'facebook',   'uses'=>'SocialController@getFacebookLogin'));                                                                                                          
    Route::get('logout',array('as'=>'logout','uses'=>'SocialController@getLoggedOut'));

您需要将命名空间添加到您的混合身份验证 class。目前,当您尝试实例化 Hybrid_Auth 对象时,它找不到 class 定义。

这是我对 Laravel 的设置:

app/Providers/AppServiceProvider.php

public function register()
{
    $this->app->bind('Hybrid_Auth', function($app) {
        return new \Hybrid_Auth(config_path('hybridauth.php'));
    });
}

config/hybridauth.php

<?php

return [
  'base_url' => env('APP_URL').'/auth/endpoint',
  'providers' => [
    'Facebook' => [
        'enabled' => true,
        'display' => 'popup',
        'keys' => [
            'id' => 'xxxx', 
            'secret' => 'xxx' 
        ],
        'scope' => 'email'
    ],
  ] 
];

app/Http/routes.php

Route::group(['prefix' => 'auth'], function()
{
  Route::get('login', 'AuthenticateController@login');
  Route::get('endpoint', 'AuthenticateController@endpoint');
  Route::get('logout', 'AuthenticateController@logout');
});

app/Http/Controllers/AuthenticateController.php

public function login(\Hybrid_Auth $auth) 
{
    $provider = $auth->authenticate('facebook');
    $profile = $provider->getUserProfile();

    $user = User::where('facebook', '=', $profile->identifier);

    if($user->first()) {
        return response()->json(['token' => $this->signin($user->first())]);
    } else {
        $user = new User;
        $user->facebook = $profile->identifier;
        $user->save();

        return response()->json(['token' =>  $this->signin($user)]);
    }
}

public function endpoint() {
    \Hybrid_Endpoint::process();
}

public function logout(\Hybrid_Auth $auth) {
    $auth->logoutAllProviders();
}