how to handle laravel socialite "Missing authorization Exception" how to handle laravel socialite "Missing authorization Exception" laravel laravel

how to handle laravel socialite "Missing authorization Exception"


Finally i got answer.Here it is

public function handleProviderCallback(){    try {        $user = Socialite::driver('facebook')->user();    } catch (\Exception $e) {        //Here you can write excepion Handling Logic    }}


Try catch didn't give good result to me. I used below methods to catch this error. If you're using Laravel Socialite library definitely it has function call handleProviderCallback. In that use this code

handleProviderCallback Method

/** * Obtain the user information from GitHub. * * @return Response */public function handleProviderCallback(){    $error_code = Input::get('error_code');    if ($error_code == 200)    {        return redirect()->route('sign-in')->with('error','You\'ve chose not to grant us permission to connect with your Facebook account.');    }    else    {        $fbUser = Socialite::driver('facebook')->user();        # rest of your code    }}

Where does this error_code come from ??

Well, If you look at the error page(Laravel Black screened) come to you check the URL of that page. It has the these get methods error , error_code , error_description , error_reason , state.

Ex : http://localhost:8000/login/facebook/callback?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=mIxNjoDCogT2piMV5LX1Imk6GWNzqPUt3JZaqsIo#_=_


What I can do this to optimize this

You can use a switch statement based on error Check this Facebook error codes, with an error message and pass it.