大佬教程收集整理的这篇文章主要介绍了谷歌回调 url 返回在 Laravel Socialite 中找不到的页面,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在我的 Web 应用程序中使用 Google 构建登录,并且我正在使用一个名为 sociallite 的库。从响应中调用 Google 回调 url 时出现错误。 它在本地主机上运行良好,但在实时服务器上运行不正常。 作为参考,您可以查看此 Site。这里只有我收到错误。
LoginController.php
<?php
namespace App\http\Controllers\Auth;
use App\http\Controllers\Controller;
use App\Models\User;
use App\ProvIDers\RouteserviceProvIDer;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = RouteserviceProvIDer::HOME;
public function __construct()
{
$this->mIDdleware('guest')->except('logout');
}
// Google login
public function redirectToGoogle()
{
return Socialite::driver('Google')->redirect();
}
// Google callBACk
public function handleGoogleCallBACk()
{
$user = Socialite::driver('Google')->user();
$this->_registerOrLoginUser($user);
// Return home after login
return redirect()->route('home');
}
protected function _registerOrLoginUser($data)
{
$user = User::where('email','=',$data->email)->first();
if (!$user) {
$user = new User();
$user->name = $data->name;
$user->email = $data->email;
$user->provIDer_ID = $data->ID;
$user->avatar = $data->avatar;
$user->save();
}
Auth::login($user);
}
}
路由 (routes/web.php)
Auth::routes();
Route::get('/',[App\http\Controllers\HomeController::class,'index'])->name('home');
Route::post('/topic/add','addtopic'])->name('topic.add');
// Google login
Route::get('/login/Google',[App\http\Controllers\Auth\LoginController::class,'redirectToGoogle'])->name('login.Google');
Route::get('/login/Google/callBACk','handleGoogleCallBACk']);
'Google' => [
'clIEnt_ID' => env('Google_CLIENT_ID'),'clIEnt_secret' => env('Google_CLIENT_SECRET'),'redirect' => 'http://localhost/cnews/public/login/Google/callBACk',],
开发者控制台中的 Google 控制台 URI。
URI*
授权的重定向 URI
我经历了很多答案,但似乎没有任何效果,其中一些是
Code for Facebook and Google Login not working on live server
Laravel Google callBACk url is giving error ("Not found")
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的谷歌回调 url 返回在 Laravel Socialite 中找不到的页面全部内容,希望文章能够帮你解决谷歌回调 url 返回在 Laravel Socialite 中找不到的页面所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。