Not getting logged out using google+ api in php -
this php code user info using google plus api. had unset access token in case user click logout still logout don't works. 1 time got info of user, after logging out , connecting 1 time again still got same user info , no alternative sign in different email id.
<?php error_reporting(e_error | e_parse); include_once "templates/base.php"; session_start(); set_include_path("google-api-php-client-master/src/" . path_separator . get_include_path()); require_once 'google/client.php'; require_once 'google/service/plus.php'; require_once 'google/service/oauth2.php'; $client_id = '554944507188-jvl2lg6l70dfmee1qad8rguircdfesba.apps.googleusercontent.com'; $client_secret = '-kcfgfqwdhk9sdnoo8lc9n6a'; $redirect_uri = 'http://localhost:81/googleplus/redirect.php'; $client = new google_client(); $client->setclientid($client_id); $client->setclientsecret($client_secret); $client->setredirecturi($redirect_uri); $client->setdeveloperkey('aizasycwdr3jgvgoz0lpx9r6hjp4y00j-r2ksgg'); $plus = new google_service_plus($client); $google_oauthv2 = new google_service_oauth2($client); $client->setscopes('https://www.googleapis.com/auth/plus.login'); $client->setscopes('email'); /************************************************ if we're logging out need clear our local access token in case ************************************************/ if (isset($_request['logout'])) { unset($_session['access_token']); } /************************************************ if have code oauth 2.0 flow, need exchange authenticate() function. store resultant access token bundle in session, , redirect ourself. ************************************************/ if (isset($_get['code'])) { $client->authenticate($_get['code']); $_session['access_token'] = $client->getaccesstoken(); $redirect = 'http://' . $_server['http_host'] . $_server['php_self']; header('location: ' . filter_var($redirect, filter_sanitize_url)); } /************************************************ if have access token, can create requests, else generate authentication url. ************************************************/ if (isset($_session['access_token']) && $_session['access_token']) { $client->setaccesstoken($_session['access_token']); } else { $authurl = $client->createauthurl(); } /************************************************ if we're signed in can go ahead , retrieve id token, part of bundle of info exchange in authenticate step - need network phone call if have retrieve google certificate verify it, , can cached. ************************************************/ if ($client->getaccesstoken()) { $_session['access_token'] = $client->getaccesstoken(); $token_data = $client->verifyidtoken()->getattributes(); $user = $google_oauthv2->userinfo->get(); $me = $plus->people->get('me'); } echo pageheader("google+ api info retrival"); if ( $client_id == ' ' || $client_secret == ' ' || $redirect_uri == ' ') { echo missingclientsecretswarning(); } ?> <div class="box"> <div class="request"> <?php if (isset($authurl)): ?> <a class='login' href='<?php echo $authurl; ?>'>connect me!</a> <?php else: ?> <a class='logout' href='index.php?logout'>logout</a> <?php endif ?> </div> </div>
how this?
if (isset($_request['logout'])) { unset($_session['access_token']); header('location: https://www.google.com/accounts/logout?continue=https://appengine.google.com/_ah/logout?continue=http://' . $_server['http_host'] . $_server['php_self']); } php google-api google-api-php-client google-api-client
No comments:
Post a Comment