Saturday, 28 July 2018

Why the login with facebook is not working? (How to debug this issue besides check the urls?)

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."

But the urls were 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);
        }
    }
}

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

When teh user click in the Login with facebook button where appears the error the url changes to "https://www.facebook.com/v3.0/dialog/oauth?client_id=....&redirect_uri=http%3A%2F%proj.test%2...&scope=email&response_type=code&state=....". There is "proj.test" that is the url to access the project in localhost I dont know why it appears there if in the basic and advanced settings are only defined the ngrok.io url´s and Im using the url with ngrok.io to access the page that has the login with facebook button.

In app.php file:

'url' => env('APP_URL', 'http://localhost'),

In .env file:

APP_URL=https://....ngrok.io



from Why the login with facebook is not working? (How to debug this issue besides check the urls?)

No comments:

Post a Comment