Пример #1
0
if (!defined('IN_FORMA')) {
    die('You can\'t access!');
}
/* ======================================================================== \
|   FORMA - The E-Learning Suite                                            |
|                                                                           |
|   Copyright (c) 2013 (Forma)                                              |
|   http://www.formalms.org                                                 |
|   License  http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt           |
|                                                                           |
\ ======================================================================== */
use OAuth\OAuth2\Service\Google;
use OAuth\Common\Storage\Session;
use OAuth\Common\Consumer\Credentials;
$social = new Social();
$social->includeGoogleLib();
$client_id = Get::sett('social_google_client_id');
$client_secret = Get::sett('social_google_secret');
//$redirect_uri = Get::sett('url').'index.php?modname=login&op=google_login';
$protocol = (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' or isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https' or isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) == 'on') ? 'https' : 'http';
$redirect_uri = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '?modname=login&op=google_login';
try {
    $serviceFactory = new \OAuth\ServiceFactory();
    $storage = new Session();
    $credentials = new Credentials($client_id, $client_secret, $redirect_uri);
    $googleService = $serviceFactory->createService('google', $credentials, $storage, array('userinfo_email'));
    //, 'userinfo_profile'
    // google login
    // 1. no params $_REQUEST or $_REQUEST['connect'] -> GOTO URL AUTH OR CONNECT GOOGLE ACCOUNT
    // 2. $_REQUEST['code'] -> RETURN OK FROM GOOGLE AUTH
    // 3. $_REQUEST['error'] -> RETURN CANCEL FROM GOOGLE AUTH