简体   繁体   中英

PHP HybridAuth: How to redirect to the “Allow” page of the selected social network?

I'm having some issues with HybridAuth when I need to redirect "a non-registered user in my local database", to the selected social network: facebook, twitter, windows live, linkedin, openid, etc, more presiously to the "Allow" and "Cancel" page!?

Till now I've got this code going on:

try {
    // $via for instance can be: Twitter, Facebook, etc
    $hybridauth = new Hybrid_Auth( $myConfig );
    $via = ucfirst($via);
    $adapter = $hybridauth->authenticate( $via ); // from this line some redirecting accoures

    if( $hybridauth->isConnectedWith( $via ) ){
        $user = $hybridauth->authenticate($via)->getUserProfile();
    }

    $profile = Users::model()->findByAttributes(array(
        'networkName' => $via,
        'networkId' => $user->identifier,
    ));

    if(!is_null($profile)) {
        // do a login
    } else {
        // do a registration + login
    }
} catch(Exception $e) {
    echo "Error: please try again!";
    echo "Original error message: " . $e->getMessage();
    die();
}

I hope I've made my point clear. Thanks for all assistance in this matter!

The way I do is to store the provider and the provider identifier in a database, which seems to be the way you implemented as well.

If the user does not exist, I create it and then redirect the user to the user profile editor. Otherwise I just redirect to the main page or dashboard.

The provider data has all the required fields for creating a basic profile. If you need something else, redirect the user to a page with a form for him to complete the registration. Store anything else you need in SESSION or similar. You can use $hybridauth->restoreSessionData($_SESSION['HYBRID']) to keep the session on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM