Server IP : 192.64.112.168 / Your IP : 3.145.186.132 Web Server : Apache System : Linux nc-ph-2300-85.bluforrest.com 4.18.0-513.9.1.el8_9.x86_64 #1 SMP Sat Dec 2 05:23:44 EST 2023 x86_64 User : expressoneac ( 1128) PHP Version : 8.0.30 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/expressoneac/www/wp-content/plugins/woodmart-core/vendor/opauth/google/ |
Upload File : |
<?php /** * Google strategy for Opauth * based on https://developers.google.com/accounts/docs/OAuth2 * * More information on Opauth: http://opauth.org * * @copyright Copyright © 2012 U-Zyn Chua (http://uzyn.com) * @link http://opauth.org * @package Opauth.GoogleStrategy * @license MIT License */ /** * Google strategy for Opauth * based on https://developers.google.com/accounts/docs/OAuth2 * * @package Opauth.Google */ class GoogleStrategy extends OpauthStrategy{ /** * Compulsory config keys, listed as unassociative arrays */ public $expects = array('client_id', 'client_secret'); /** * Optional config keys, without predefining any default values. */ public $optionals = array('redirect_uri', 'scope', 'state', 'access_type', 'approval_prompt'); /** * Optional config keys with respective default values, listed as associative arrays * eg. array('scope' => 'email'); */ public $defaults = array( 'redirect_uri' => '{complete_url_to_strategy}oauth2callback', 'scope' => 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email' ); /** * Auth request */ public function request(){ $url = 'https://accounts.google.com/o/oauth2/auth'; $params = array( 'client_id' => $this->strategy['client_id'], 'redirect_uri' => $this->strategy['redirect_uri'], 'response_type' => 'code', 'scope' => $this->strategy['scope'] ); foreach ($this->optionals as $key){ if (!empty($this->strategy[$key])) $params[$key] = $this->strategy[$key]; } $this->clientGet($url, $params); } /** * Internal callback, after OAuth */ public function oauth2callback(){ if (array_key_exists('code', $_GET) && !empty($_GET['code'])){ $code = $_GET['code']; $url = 'https://accounts.google.com/o/oauth2/token'; $params = array( 'code' => $code, 'client_id' => $this->strategy['client_id'], 'client_secret' => $this->strategy['client_secret'], 'redirect_uri' => $this->strategy['redirect_uri'], 'grant_type' => 'authorization_code' ); $response = $this->serverPost($url, $params, null, $headers); $results = json_decode($response); if (!empty($results) && !empty($results->access_token)){ $userinfo = $this->userinfo($results->access_token); $this->auth = array( 'uid' => $userinfo['id'], 'info' => array(), 'credentials' => array( 'token' => $results->access_token, 'expires' => date('c', time() + $results->expires_in) ), 'raw' => $userinfo ); if (!empty($results->refresh_token)) { $this->auth['credentials']['refresh_token'] = $results->refresh_token; } $this->mapProfile($userinfo, 'name', 'info.name'); $this->mapProfile($userinfo, 'email', 'info.email'); $this->mapProfile($userinfo, 'given_name', 'info.first_name'); $this->mapProfile($userinfo, 'family_name', 'info.last_name'); $this->mapProfile($userinfo, 'picture', 'info.image'); $this->callback(); } else{ $error = array( 'code' => 'access_token_error', 'message' => 'Failed when attempting to obtain access token', 'raw' => array( 'response' => $response, 'headers' => $headers ) ); $this->errorCallback($error); } } else{ $error = array( 'code' => 'oauth2callback_error', 'raw' => $_GET ); $this->errorCallback($error); } } /** * Queries Google API for user info * * @param string $access_token * @return array Parsed JSON results */ private function userinfo($access_token){ $userinfo = $this->serverGet('https://www.googleapis.com/oauth2/v1/userinfo', array('access_token' => $access_token), null, $headers); if (!empty($userinfo)){ return $this->recursiveGetObjectVars(json_decode($userinfo)); } else{ $error = array( 'code' => 'userinfo_error', 'message' => 'Failed when attempting to query for user information', 'raw' => array( 'response' => $userinfo, 'headers' => $headers ) ); $this->errorCallback($error); } } }