I have the code below to login with Facebook. But it's not working it shows:
“Can't Load URL: The domain of this URL isn't
included in the App's domains. To be able to
load this URL, add all domains and subdomains of your app to the
App Domains field in your app settings."
But the URL was defined.
Routes:
Route::get('auth/{provider}', [
'uses' => 'OauthController@redirectToProvider',
'as' => 'social.auth'
]);
Route::get('auth/{provider}/callback', [
'uses' => 'OauthController@handleProviderCallback',
]);
services.php:
'facebook' => [
'client_id' => '...',
'client_secret' => '...',
'redirect' => 'https://....ngrok.io/auth/facebook/callback'
]
OauthController:
class OauthController extends Controller
{
public function redirectToProvider($provider)
{
return Socialite::driver($provider)->redirect();
}
public function handleProviderCallback($provider)
{
$userFace = Socialite::driver($provider)->user();
// $user->token;
$findUser = User::where('email', $userFace->email)->first();
if($findUser){
Auth::login($findUser);
}else{
$user = new User;
$user->name = $userFace->name;
$user->surname = "";
$user->email = $userFace->email;
$user->password = bcrypt($user->name);
$user->save();
Auth::login($user);
}
}
}
I change some configurations and now it appears a different error. The user clicks in "Login with Facebook" button and is redirected to the facebook page and is necessary to introduce the password. After introducing the password the user is redirected to "https://....ngrok.io/auth/facebook/callback?code=...&state=...#=" and it appears a page with:
Laravel \ Socialite \ Two \ InvalidStateException
No message
This error is in the file /socialite/src/Two/AbstractProvider.php in "public function user() { if ($this->hasInvalidState()) { throw new InvalidStateException;}... "
Configurations:
Laravel configurations:
In services.php
'redirect' => 'https://....ngrok.io/facebook/auth/callback'
In .env file:
APP_URL=https://....ngrok.io
Facebook settings:
Client OAuth Login - yes
Web OAuth login - yes
Force Web OAuth Reauthentication - yes
Use Strict Mode for Redirect URIs - yes
Enforce HTTPS - No
Embedded Browser OAuth Login - No
Valid OAuth Redirect URIs: https://....ngrok.io/facebook/auth/callback
Basic settings:
App domains: ....ngrok.io
Site URL: https://....ngrok.io/facebook/callback
If I use localhost it works.
With "'redirect' => 'proj.test/auth/facebook/callback'";.
And in facebook settings:
Site url: proj.test/auth/facebook/callback
App domains: proj.test
Valid OAuth Redirect URIs proj.test/auth/facebook/callback'"
However its not working properly, the user is redirected to "proj.test/auth/facebook/callback?code=......=";, its inserted in the DB but it appears a blank page instead of the user being redirected to the "proj.test".