在 laravel 5 中集成 hybrid_auth
Posted
技术标签:
【中文标题】在 laravel 5 中集成 hybrid_auth【英文标题】:Integration of hybrid_auth in laravel 5 【发布时间】:2015-09-15 12:32:08 【问题描述】:我是 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> 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'));
【问题讨论】:
任何替代 API 都具有正确的指导方针,说明如何在 laravel 5 中集成社交登录/注册/注销,现在都可以使用。或任何可以为我投票的人。 【参考方案1】:这是我对 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();
【讨论】:
【参考方案2】:您需要将命名空间添加到您的 Hybrid Auth 类。目前,当您尝试实例化 Hybrid_Auth 对象时,它没有找到类定义。
【讨论】:
你可以通过这个教程:hasin.me/2014/02/10/… 感谢您的回复,我必须将 Api 从 Hybrid Oauth 更改为 Socialite,我发现本教程很有帮助 Socialite-Laravel-5@Muhammad以上是关于在 laravel 5 中集成 hybrid_auth的主要内容,如果未能解决你的问题,请参考以下文章