Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adamjhn's avatar

Login with facebook is not working

I have the code below to login with facebook. But its 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.".

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);
            }
        }
    }

In Facebook I just edited the basic settings:


App Domains: https://...ngrok.io/
    
Site URL: https://...ngrok.io/auth/facebook/callback

Valid Oauth redirect URIs: https://...ngrok.io/auth/facebook/callback and "https://....ngrok.io/" 

Use strict mode for Redirect URIS: yes

0 likes
9 replies
Cronix's avatar

It looks like it's because you are using this on your dev domain "app.test" instead of your actual domain that facebook can access to redirect to... The domain needs to be publicly reachable on the internet. Facebook needs to be able to access it.

1 like
adamjhn's avatar

Thanks, but Im using ngrok, on local machine but using ngrok, so it should be public right? And the url´s in the app settings were defined with the ngrok url´s.

Cronix's avatar

Sure, but "app.test" isn't the publicly accessible ngrok address. If it was, I could access it by going to http://app.test from here. It would be something like http://04f7a6a8.ngrok.io

To share a site, navigate to the site's directory in your terminal and run the valet share command. A publicly accessible URL will be inserted into your clipboard and is ready to paste directly into your browser. That's it.

That's the url you need to register with facebook...

https://laravel.com/docs/5.6/valet#sharing-sites

1 like
adamjhn's avatar

Thanks, to create the ngrok url I used valet share and generated an http and an https url. In facebook settings I defiend the https url:

In Facebook I just edited the basic settings like:


 App Domains defined: https://44....ngrok.io/
    
Site URL: https://44...ngrok.io/auth/facebook/callback

Valid Oauth redirect URIs: https://44...ngrok.io/auth/facebook/callback and https://44...ngrok.io/ 


Cronix's avatar

Are you saying it's working now?

Something wasn't set up right because in your 2nd post, you said it had this

https://www.facebook.com/v3.0/dialog/oauth?client_id=....&redirect_uri=http%3A%2F%app.test%2...&scope=email&response_type=code&state=....%22

notice the domain it said for the redirect was "http://app.test". So you gave them that url somewhere or it wouldn't redirect to it. It would have redirected to https://44...ngrok.io/facebook/auth/callback

adamjhn's avatar

No, its not working, but in the app setttings the url´s are defined like that using ngrok. So I dont understand why in the redirect_uri appears that "http://app.test".

adamjhn's avatar

Do you know how the issue can be debuged besides check if the urls are correct?

Please or to participate in this conversation.