Laravel Google回调URL出现错误(&Q;找不到&Q;)

我正在使用社交帐户登录,目前正在使用谷歌帐户进行测试。我使用了Laravel社会名流,阅读了文档,做了所有的事情。我在下面分享了我的代码,有人知道我做错了什么吗?

<?php
  
namespace AppHttpControllersAuth;
  
use AppHttpControllersController;
use Socialite;
use Auth;
use Exception;
use AppUser;
  
class GoogleController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function redirectToGoogle()
    {
        return Socialite::driver('google')->redirect();
    }
      
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function handleGoogleCallback()
    {
        try {
    
            $user = Socialite::driver('google')->user();
     
            $finduser = User::where('google_id', $user->id)->first();
     
            if($finduser){
     
                Auth::login($finduser);
    
                return redirect('/home');
     
            }else{
                $newUser = User::create([
                    'name' => $user->name,
                    'email' => $user->email,
                    'google_id'=> $user->id,
                    'password' => encrypt('123456dummy')
                ]);
    
                Auth::login($newUser);
     
                return redirect('/home');
            }
    
        } catch (Exception $e) {
            dd($e->getMessage());
        }
    }
}

我的Google回调URL

http://localhost:81/auth/google/callback?state=YMuSrsU6925bkwXG59tzHz4Ru8J2VlmOxiG9w5NS&code=4%2F0AY0e-g5f17C96cQZ0CSqtRIOUlq3RcpPj5Y1yp_0ibvDxi_U4S1WOU2QIT_0j7QlfUcabA&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=0&prompt=consent#

错误 [1]:https://i.stack.imgur.com/TNyd6.png

注意:我的所有路由都是正确的。


解决方案

检查您的谷歌授权重定向URI。

相关文章