Search code examples
twitterlaravellocalhosthybridauth

Need to Authorize app everytime - hybridauth laravel localhost


i have integrated hybridauth with laravel and able to login to my app with twitter using hybridauth. when i first time login to my app with twitter, i have authorized my app. so, generally after next time i don't need to authorize my app for login cause i have accept the authorization first time.

but it is not happening. my app is force to authorize by twitter every time i try to login twitter.

i am trying this on localhost. should i need to check it in a live server?

i am using this code, all Credential are setted:

Route::get('social/{action?}', array("as" => "hybridauth", function($action = "")
{
    // check URL segment
    if ($action == "auth") {
        // process authentication
        try {
            Hybrid_Endpoint::process();
        }
        catch (Exception $e) {
            // redirect back to http://URL/social/
            return Redirect::route('hybridauth');
        }
        return;
    }
    try {
        // create a HybridAuth object
        $socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
        // authenticate with Google
        $provider = $socialAuth->authenticate("Twitter");
        // fetch user profile
        $userProfile = $provider->getUserProfile();
    }
    catch(Exception $e) {
        // exception codes can be found on HybBridAuth's web site
        return $e->getMessage();
    }
    // access user profile data
    echo "Connected with: <b>{$provider->id}</b><br />";
    echo "As: <b>{$userProfile->displayName}</b><br />";
    echo "<pre>" . print_r( $userProfile, true ) . "</pre><br />";

    // logout
    $provider->logout();
}));

Solution

  • I have found the solution. it was not in the code to fix something. It was the settings of the twitter app. To avoid this kind of problem, you should select Read and Write option rather than Read, Write and Access direct messages option from the Permission section of your app's settings.

    If you select Read, Write and Access direct messages, then twitter will always prompt you to authorize your app whenever you try to login in your app via your twitter app. See the Image bellow for more clear information.

    Hope it will help you. Thanks See the Image