在laravel 5.4中使用社交laravel包时重定向太多次

jk9hmnmh  于 2023-05-30  发布在  其他
关注(0)|答案(1)|浏览(230)

我已经在我的应用程序中安装了socialite包,但它不能正常工作。
在我的登录与linkedin按钮,我给了网址如下

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');
    }
}
}

当我点击linkedin登录后,它会出现**redirectToLinkedin()**函数,但我得到了类似的错误
此页面不存在!返回首页尝试清除您的Cookie。错误_太多_重定向
我的代码有什么问题?

dgtucam1

dgtucam11#

在.env文件中有一个LINKEDIN_REDIRECT或其他内容。确保该值指向回调链接,而不是重定向链接。

相关问题