当前位置: 首页>>代码示例>>PHP>>正文


PHP Google_Client::authenticate方法代码示例

本文整理汇总了PHP中Google_Client::authenticate方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::authenticate方法的具体用法?PHP Google_Client::authenticate怎么用?PHP Google_Client::authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Google_Client的用法示例。


在下文中一共展示了Google_Client::authenticate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionToken

 public function actionToken()
 {
     //$this->checkAccess("token");
     $client = new \Google_Client();
     $client->setClientId(Yii::$app->params['OAUTH2_CLIENT_ID']);
     $client->setClientSecret(Yii::$app->params['OAUTH2_CLIENT_SECRET']);
     $client->setScopes('https://www.googleapis.com/auth/youtube');
     //$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL);
     $client->setRedirectUri(Yii::$app->params['redirectVideo']);
     if (Yii::$app->request->get('code')) {
         if (strval(Yii::$app->session->get('state')) !== strval(Yii::$app->request->get('state'))) {
             die('The session state did not match.');
         }
         $client->authenticate(Yii::$app->request->get('code'));
         if ($client->getAccessToken()) {
             $token = $this->getToken();
             $token->load(json_decode($client->getAccessToken(), true), "");
             $token->save();
             return ["token_saved" => $token];
         }
         return ["token_not_saved_code" => Yii::$app->request->get('code')];
     }
     if (!$client->getAccessToken()) {
         // If the user hasn't authorized the app, initiate the OAuth flow
         //$state = mt_rand();
         $client->setState(Yii::$app->params['stateVideo']);
         $client->setAccessType("offline");
         $client->setApprovalPrompt("force");
         Yii::$app->session->set('state', Yii::$app->params['stateVideo']);
         $authUrl = $client->createAuthUrl();
         return ["link" => $authUrl];
     }
 }
开发者ID:pylypen,项目名称:api-side,代码行数:33,代码来源:VideoController.php

示例2: google

 function google()
 {
     $client = new Google_Client();
     $client->setApplicationName("snmmaurya");
     $client->setClientId(CLIENT_ID);
     $client->setClientSecret(CLIENT_SECRET);
     $client->setRedirectUri(REDIRECT_URI);
     $client->setApprovalPrompt(APPROVAL_PROMPT);
     $client->setAccessType(ACCESS_TYPE);
     $oauth2 = new Google_Oauth2Service($client);
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['token'] = $client->getAccessToken();
     }
     if (isset($_SESSION['token'])) {
         $client->setAccessToken($_SESSION['token']);
     }
     if (isset($_REQUEST['error'])) {
         echo '<script type="text/javascript">window.close();</script>';
         exit;
     }
     if ($client->getAccessToken()) {
         $user = $oauth2->userinfo->get();
         $_SESSION['User'] = $user;
         $_SESSION['token'] = $client->getAccessToken();
     } else {
         $authUrl = $client->createAuthUrl();
         header('Location: ' . $authUrl);
     }
 }
开发者ID:business-expert,项目名称:bellimodeling,代码行数:30,代码来源:google.php

示例3: getGoogleApiClient

 /**
  * Returns an authorized API client.
  * @return Google_Client the authorized client object
  */
 private function getGoogleApiClient()
 {
     $client = new Google_Client();
     $client->setApplicationName($this->CFG['GOOGLE_API_APPLICATION_NAME']);
     $client->setScopes(Google_Service_Calendar::CALENDAR);
     $client->setAuthConfigFile($this->CFG['GOOGLE_API_CLIENT_SECRET_PATH']);
     $client->setAccessType('offline');
     // Load previously authorized credentials from a file.
     $credentialsPath = $this->CFG['GOOGLE_API_CREDENTIALS_PATH'];
     if (file_exists($credentialsPath)) {
         $accessToken = file_get_contents($credentialsPath);
     } else {
         // Request authorization from the user.
         $authUrl = $client->createAuthUrl();
         printf("Open the following link in your browser:\n%s\n", $authUrl);
         print 'Enter verification code: ';
         $authCode = trim(fgets(STDIN));
         // Exchange authorization code for an access token.
         $accessToken = $client->authenticate($authCode);
         // Store the credentials to disk.
         if (!file_exists(dirname($credentialsPath))) {
             mkdir(dirname($credentialsPath), 0700, true);
         }
         file_put_contents($credentialsPath, $accessToken);
         printf("Credentials saved to %s\n", $credentialsPath);
     }
     $client->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         file_put_contents($credentialsPath, $client->getAccessToken());
     }
     return $client;
 }
开发者ID:neocodesoftware,项目名称:NeoCode-FmUsage,代码行数:38,代码来源:class.GoogleApi.php

示例4: login

 /**
  * @param $code
  * @return string
  */
 public function login($code)
 {
     $this->client->authenticate($code);
     $token = $this->client->getAccessToken();
     \Session::put('token', $token);
     return $token;
 }
开发者ID:janusnic,项目名称:YoutubeAPI_Demo,代码行数:11,代码来源:GoogleLogin.php

示例5: cmdLineAuth

 /**
  * Auth over command line
  */
 public function cmdLineAuth()
 {
     $authUrl = $this->client->createAuthUrl();
     //Request authorization
     print "Please visit:\n{$authUrl}\n\n";
     print "Please enter the auth code:\n";
     $authCode = trim(fgets(STDIN));
     // Exchange authorization code for access token
     $accessToken = $this->client->authenticate($authCode);
     $this->client->setAccessToken($accessToken);
     $this->accessToken = $accessToken;
     $this->refreshToken = $this->client->getRefreshToken();
 }
开发者ID:p13eater,项目名称:google-helper,代码行数:16,代码来源:GoogleHelper.php

示例6: authenticate

 /**
  * Goes through the client authorization routine. This routine both
  * redirects a user to the Google Accounts authorization screen as well as
  * handle the response from the authorization service to retrieve the
  * authorization code then exchange it for an access token. This method
  * also removes the authorization code from the URL to keep things pretty.
  * Details on how the apiClient implements authorization can be found here:
  * http://code.google.com/p/google-api-php-client/source/browse/trunk/src/auth/apiOAuth2.php#84
  * If an authorization error occurs, the exception is caught and the error
  * message is saved in $error.
  */
 public function authenticate()
 {
     try {
         $accessToken = $this->client->authenticate();
         $this->storage->set($accessToken);
         // Keep things pretty. Removes the auth code from the URL.
         if ($_GET['code']) {
             header("Location: {$this->controllerUrl}");
         }
     } catch (Google_AuthException $e) {
         $this->errorMsg = $e->getMessage();
     }
 }
开发者ID:ricain59,项目名称:fortaff,代码行数:24,代码来源:authHelper.php

示例7: authenticateUser

 /**
  * {@inheritDoc}
  */
 public function authenticateUser(Request $request)
 {
     if (!$request->query->has('code')) {
         throw new NotAuthorizedException("There's missing authorization code");
     }
     $fosUserBuilder = new FOSUserBuilder($this->userManager);
     $oauth2 = new \Google_Service_Oauth2($this->client);
     try {
         $this->client->authenticate($request->query->get('code'));
     } catch (\Google_Auth_Exception $e) {
         throw new NotAuthorizedException(401, "XSolve Google Auth couldn't authorize user", $e);
     }
     return $fosUserBuilder->build((array) $oauth2->userinfo->get()->toSimpleObject());
 }
开发者ID:xsolve-pl,项目名称:xsolve-google-auth-bundle,代码行数:17,代码来源:GoogleAuthenticator.php

示例8: getClient

function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setAccessType('offline');
    $credentialsPath = CREDENTIALS_PATH;
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        $authUrl = $client->createAuthUrl();
        printf("Open the following link in your browser:\n%s\n", $authUrl);
        print 'Enter verification code: ';
        $authCode = trim(fgets(STDIN));
        $accessToken = $client->authenticate($authCode);
        if (!file_exists(dirname($credentialsPath))) {
            mkdir(dirname($credentialsPath), 0700, true);
        }
        file_put_contents($credentialsPath, $accessToken);
        printf("Credentials saved to %s\n", $credentialsPath);
    }
    $client->setAccessToken($accessToken);
    if ($client->isAccessTokenExpired()) {
        $client->refreshToken($client->getRefreshToken());
        file_put_contents($credentialsPath, $client->getAccessToken());
    }
    return $client;
}
开发者ID:atsanna,项目名称:PHP-Custom-Floorplan-for-Domoticz,代码行数:29,代码来源:gcal.php

示例9: get

 public function get()
 {
     $callback = 'http://api.soundeavor.com/User/Auth/Login/Google/index.php';
     $config = new \Google_Config();
     $config->setApplicationName('Soundeavor');
     $config->setClientId(Config::getConfig('GoogleClientId'));
     $config->setClientSecret(Config::getConfig('GoogleClientSecret'));
     $config->setRedirectUri($callback);
     $client = new \Google_Client($config);
     /*
      * Add scopes (permissions) for the client https://developers.google.com/oauthplayground/
      */
     $client->addScope('https://www.googleapis.com/auth/plus.me');
     if (!isset($_GET['code'])) {
         $loginUrl = $client->createAuthUrl();
         header('Location: ' . $loginUrl);
     }
     $code = $_GET['code'];
     $client->authenticate($code);
     $accessToken = $client->getAccessToken();
     $accessToken = $accessToken['access_token'];
     $service = new \Google_Service_Plus($client);
     $scopes = $service->availableScopes;
     print_r($scopes);
     die;
 }
开发者ID:kris-nova,项目名称:API,代码行数:26,代码来源:Google.php

示例10: authorizeGoogleUser

 function authorizeGoogleUser($access_code)
 {
     $client = new \Google_Client();
     $google = $this->config->google;
     $client->setApplicationName('Portal da Rede');
     $client->setClientId($google->clientId);
     $client->setClientSecret($google->secret);
     $client->setRedirectUri('postmessage');
     $client->addScope('https://www.googleapis.com/auth/userinfo.profile');
     $client->addScope('https://www.googleapis.com/auth/userinfo.email');
     $client->authenticate($access_code);
     $json_token = $client->getAccessToken();
     $client->setAccessToken($json_token);
     $plus = new \Google_Service_Plus($client);
     $user = $plus->people->get('me');
     if (!$user->emails || !is_array($user->emails)) {
         return;
     }
     $email = $user->emails[0]['value'];
     $user_email = $this->db->user_email->find_one($email);
     if (!$user_email) {
         return;
     }
     $this->login($user_email->user);
 }
开发者ID:kahvazquez,项目名称:trouble,代码行数:25,代码来源:User.php

示例11: catch

    /**
     * Check, if the analytics account is authenticated and has an access token.
     * Authenticate it, if it is not.
     *
     * TODO: have the access token in a transient and check if the token expired before continuing
     *
     * @return bool
     */
    function is_app_authenticated()
    {
        $access_token = WooCommerce_Grow_Helpers::get_option('access_token');
        // We have an access token already
        if (!empty($access_token)) {
            try {
                $this->client->setAccessToken($access_token);
            } catch (Exception $e) {
                echo sprintf(__('Error: Unable to set Google Analytics access token. Error Code: %s. Error Message: %s  ', 'woocommerce-grow'), $e->getCode(), $e->getMessage());
                return false;
            }
        } else {
            $settings = get_option('woocommerce_woocommerce_grow_settings', array());
            $auth_code = WooCommerce_Grow_Helpers::get_field('authorization_token', $settings);
            if (empty($auth_code)) {
                // TODO: needs behavior
                return false;
            }
            try {
                // The authenticate method gets an access token, sets the access token
                // and returns the access token all at once.
                $access_token = $this->client->authenticate($auth_code);
                $this->client->setAccessToken($access_token);
                WooCommerce_Grow_Helpers::update_option('access_token', $access_token);
            } catch (Exception $e) {
                echo sprintf(__('Google Analytics was unable to authenticate you.
						Please refresh and try again. If the problem persists, please obtain a new authorizations token.
						Error Code: %s. Error Message: %s  ', 'woocommerce-grow'), $e->getCode(), $e->getMessage());
                return false;
            }
        }
        return true;
    }
开发者ID:raisonon,项目名称:woocommerce-grow,代码行数:41,代码来源:class-woocommerce-grow-google-analytics.php

示例12: login

 /**
  * Login to facebook and get the associated cloudrexx user.
  */
 public function login()
 {
     $client = new \Google_Client();
     $client->setApplicationName('Contrexx Login');
     $client->setClientId($this->applicationData[0]);
     $client->setClientSecret($this->applicationData[1]);
     $client->setRedirectUri(\Cx\Lib\SocialLogin::getLoginUrl(self::OAUTH_PROVIDER));
     $client->setDeveloperKey($this->applicationData[2]);
     $client->setUseObjects(true);
     $client->setApprovalPrompt('auto');
     $client->setScopes(self::$scopes);
     self::$google = new \Google_Oauth2Service($client);
     self::$googleplus = new \Google_PlusService($client);
     if (isset($_GET['code'])) {
         try {
             $client->authenticate();
         } catch (\Google_AuthException $e) {
         }
     }
     if (!$client->getAccessToken()) {
         \Cx\Core\Csrf\Controller\Csrf::header('Location: ' . $client->createAuthUrl());
         exit;
     }
     self::$userdata = $this->getUserData();
     $this->getContrexxUser(self::$userdata['oauth_id']);
 }
开发者ID:Cloudrexx,项目名称:cloudrexx,代码行数:29,代码来源:Google.class.php

示例13: bdn_is_user_auth2

function bdn_is_user_auth2()
{
    global $driveService;
    $current_user_id = get_current_user_id();
    $client = new Google_Client();
    $client->setRedirectUri(home_url('/'));
    $driveService = new Google_DriveService($client);
    $oauth2 = new Google_Oauth2Service($client);
    if (!isset($_GET['code']) && (!is_user_logged_in() || ($access_token = get_user_meta($current_user_id, '_google_access_token', true)) && $client->setAccessToken($access_token) && !$client->getAccessToken())) {
        header('Location: ' . $client->createAuthUrl());
        exit;
    }
    if (isset($_GET['code'])) {
        $client->authenticate($_GET['code']);
        $user = $oauth2->userinfo->get();
        $new_user = get_user_by('email', $user['email']);
        if (!$current_user_id) {
            wp_set_current_user($new_user->ID, $new_user->user_login);
            wp_set_auth_cookie($new_user->ID);
            do_action('wp_login', $new_user->user_login);
        } elseif ($new_user->ID == $current_user_id) {
            update_user_meta($new_user->ID, '_google_access_token', $client->getAccessToken());
        } else {
            die('Sorry, please use your BDN account');
        }
        header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
    }
    return $driveService;
}
开发者ID:bangordailynews,项目名称:Newsroom-Tools,代码行数:29,代码来源:gapi.php

示例14: getClient

function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET);
    $client->setAccessType('offline');
    // Load previously authorized credentials from a file.
    $credentialsPath = expandHomeDirectory(CREDENTIAL_PATH);
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        // Request authorization from the user.
        $authUrl = $client->createAuthUrl();
        printf("Open the following link in your browser:\n\n\t%s\n\n", $authUrl);
        print 'Enter verification code: ';
        $authCode = trim(fgets(STDIN));
        // Exchange authorization code for an access token.
        $accessToken = $client->authenticate($authCode);
        // Store the credentials to disk.
        if (!file_exists(dirname($credentialsPath))) {
            mkdir(dirname($credentialsPath), 0700, true);
        }
        file_put_contents($credentialsPath, $accessToken);
        printf("Credentials saved to %s\n", $credentialsPath);
    }
    $client->setAccessToken($accessToken);
    // Refresh the token if it's expired.
    if ($client->isAccessTokenExpired()) {
        $client->refreshToken($client->getRefreshToken());
        file_put_contents($credentialsPath, $client->getAccessToken());
    }
    return $client;
}
开发者ID:cmunky,项目名称:gcontact,代码行数:34,代码来源:gascapi.php

示例15: getClient

/**
 * Returns an authorized API client.
 * @return Google_Client the authorized client object
 */
function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName("Study Group Finder");
    $client->setAuthConfigFile(__DIR__ . '/client_secret.json');
    $client->addScope(Google_Service_Calendar::CALENDAR);
    $client->setRedirectUri(current_url());
    if (isset($_SESSION["googleauth"])) {
        $client->setAccessToken($_SESSION["googleauth"]);
        $_SESSION["googleauth"] = NULL;
        return $client;
    }
    if (!isset($_GET['code'])) {
        // Request authorization from the user.
        $authUrl = $client->createAuthUrl();
        header("Location: {$authUrl}");
        exit(0);
    }
    $authCode = $_GET['code'];
    // Exchange authorization code for an access token.
    $accessToken = $client->authenticate($authCode);
    $_SESSION["googleauth"] = $accessToken;
    header("Location: calendar.php");
    exit(0);
}
开发者ID:magical,项目名称:cs290-project,代码行数:29,代码来源:calendar.php


注:本文中的Google_Client::authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。