There seems to be no problem until authentication, but the redirect destination after authentication says, "I can't access this site."
There is no particular error indication.Please teach me.
Environment: With DockerToolbox.
Windows 10
Redirect URL in Google API
The URL set in the address field is written.
web.php
Route::prefix('login') ->name('login.') ->group(function(){
Route::get('/{provider}', 'Auth\LoginController @redirectToProvider') ->name('{provider}');
Route::get('/{provider}/callback', 'Auth\LoginController@handleProviderCallback') ->name('{provider}.callback');
});
Specifies routing.
LoginController.php
<?php
namespace App\Http\Controllers\Auth;
useApp\Http\Controllers\Controllers;
use App\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
// =========== Facade ==========
use Ravel\Socialite\Facades\Socialite;
class LoginController extensions Controller
{
// approximately
public function redirectToProvider (string$provider)
{
return Socialite::driver($provider)->redirect();
}
public function handleProviderCallback(Request$request, string$provider)
{
$providerUser=Socialite::driver($provider)->stateless()->user();
$user=User::where('email', $providerUser->getEmail()) ->first();
if($user){
$this->guard()->login($user,true);
return$this->sendLoginResponse($request);
}
}
}
login.blade.php
<h2class="h3card-title text-center mt-2">Login</h2>
<a href="{{route('login.{provider}',['provider'=>'google']}}"class="btn btn-block btn-info">
<i class="fab fa-Google mr-1">/i>Log in with Google
</a>
I solved myself.
If you are using DokcerToolbox, you will need to do something called port forwarding.
After opening a command prompt with administrator privileges and executing the following commands, you are now redirected successfully:
netsh interface portproxy add v4 tov4 listenport=80 listenaddress=127.0.0.1 connectport=80 connectaddress=192.168.99.100
netsh interface portproxy show v4 tov4
Thank you.
© 2024 OneMinuteCode. All rights reserved.