我已在我的应用程序中安装了socialite包,但它无法正常工作。
在我使用linkedin按钮登录时,我已经给出了如下所示的URL
href="{{ url('auth/linkedin') }}"
我的路线文件是
Route::get('auth/linkedin', 'LinkedInController@redirectToLinkedin');
Route::get('/linkedin/callback', 'LinkedInController@handleLinkedinCallback');
LinkedInController.php是
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Auth;
use Socialite;
use Exception;
class LinkedInController extends Controller {
protected $redirectTo = '/';
//use Illuminate\Foundation\Auth\AuthenticatesUsers;
public function __construct()
{
//$this->middleware('guest', ['except' => 'logout']);
}
protected function validator(array $data) {
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
protected function create(array $data) {
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
public function redirectToLinkedin() {
return Socialite::driver('linkedin')->redirect();
}
public function handleLinkedinCallback() {
try {
$user = Socialite::driver('linkedin')->user();
$create['name'] = $user->name;
$create['email'] = $user->email;
$create['linkedin_id'] = $user->id;
$userModel = new User;
$createdUser = $userModel->addNew($create);
Auth::loginUsingId($createdUser->id);
return redirect('/index');
} catch (Exception $e) {
return redirect('auth/linkedin');
}
}
}
点击登录后,我会看到 redirectToLinkedin()功能,但我收到错误
此页面无效 localhost重定向了你太多次了。 尝试清除您的cookie。 ERR_TOO_MANY_REDIRECTS
我的代码有问题吗?