程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了谷歌回调 url 返回在 Laravel Socialite 中找不到的页面大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决谷歌回调 url 返回在 Laravel Socialite 中找不到的页面?

开发过程中遇到谷歌回调 url 返回在 Laravel Socialite 中找不到的页面的问题如何解决?下面主要结合日常开发的经验,给出你关于谷歌回调 url 返回在 Laravel Socialite 中找不到的页面的解决方法建议,希望对你解决谷歌回调 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']);

config/services.php

'Google' => [
        'clIEnt_ID' => env('Google_CLIENT_ID'),'clIEnt_secret' => env('Google_CLIENT_SECRET'),'redirect' => 'http://localhost/cnews/public/login/Google/callBACk',],

开发者控制台中的 Google 控制台 URI。
URI*

  1. http://localhost
  2. http://internaka.com

授权的重定向 URI

  1. http://localhost/cnews/public/login/Google/callBACk
  2. http://internaka.com/xnews/public/login/google/callBACk

我经历了很多答案,但似乎没有任何效果,其中一些是
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,请注明来意。
标签:返回在