コード例 #1
0
ファイル: Googlavel.php プロジェクト: redbaron76/Googlavel
 /**
  * Authenticate with Google and get access token
  * @param  string $code - The OAuth2 callback code
  * @return bool
  */
 public function authenticate($code)
 {
     if ($code) {
         $this->client->authenticate($code);
         $access_token = $this->client->getAccessToken();
         $this->session->put('googleapi_token', $access_token);
         return true;
     }
     return false;
 }
コード例 #2
0
 /**
  * Constructor method
  *
  * This method is used to create the facebook instance, set other important
  * variables, log in and get needed Facebook permissions from user.
  *
  * @param array $params parameters
  *
  * @return void
  */
 public function __construct($params)
 {
     // Creating facebook instance.
     $this->facebook = $this->getFbInstance($params);
     // Set class variables.
     $this->permissions = $params['permissionsArray'];
     $this->afterLoginUrl = $params['afterLoginUrl'];
     // Login and check for permissions.
     $this->logIn();
     $this->accessToken = $this->facebook->getAccessToken();
     $this->askPermissions();
 }
コード例 #3
0
/**
 * Returns a list feed of the specified worksheet.
 * 
 * @param object $client GA Client
 * 
 * @return string $accessToken Access Token
 */
function getAccessToken($client)
{
    $json = $client->getAccessToken();
    $decoded = json_decode($json);
    $accessToken = $decoded->access_token;
    return $accessToken;
}
コード例 #4
0
 /**
  * 
  * @param object $Facebook The facebook object after the configuring of normal facebook api
  * @throws Exception if there is some error, loads every required resources otherwise.
  * @access public
  */
 public function __construct($Facebook)
 {
     //initialize everything we need, from facebook to xml's
     $this->Facebook = $Facebook;
     $this->appId = $Facebook->getAppId();
     $this->uid = $Facebook->getUser();
     $data = $Facebook->api('/me');
     $this->userName = $data['username'];
     $this->appSecret = $Facebook->getAppSecret();
     $this->AccessToken = $Facebook->getAccessToken();
     $this->STREAM_XML = '<stream:stream ' . 'xmlns:stream="http://etherx.jabber.org/streams" ' . 'version="1.0" xmlns="jabber:client" to="chat.facebook.com" ' . 'xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">';
     $this->AUTH_XML = '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" ' . 'mechanism="X-FACEBOOK-PLATFORM"></auth>';
     $this->CLOSE_XML = '</stream:stream>';
     $this->RESOURCE_XML = '<iq type="set" id="3">' . '<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">' . '<resource>fb_xmpp_script</resource></bind></iq>';
     $this->SESSION_XML = '<iq type="set" id="4" to="chat.facebook.com">' . '<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>';
     $this->START_TLS = '<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>';
     $this->server = 'chat.facebook.com';
     $this->options = array('uid' => $this->userName . "@chat.facebook.com", 'app_id' => $this->appId, 'server' => $this->server);
     $errno = "";
     $errstr = 0;
     $fh = fsockopen($this->server, 5222, $errno, $errstr);
     if ($fh) {
         $this->filehandle = $fh;
     } else {
         throw new Exception("fsockopen is not working, may be your server is restricting you from making outbound connections", "bad_request");
     }
 }
コード例 #5
0
 /**
  * Constructor
  *
  * @param string $user User ID (email)
  * @param string $refresh_token Saved token for specified user
  * @return void
  */
 public function __construct($user, $refresh_token)
 {
     $this->user = (string) $user;
     if (empty($user) || empty($refresh_token) || !Configure::read('LilCrm.googleApiClientId') || !Configure::read('LilCrm.googleApiClientSecret')) {
         return;
     }
     $this->Client = new OAuth2\Client(Configure::read('LilCrm.googleApiClientId'), Configure::read('LilCrm.googleApiClientSecret'));
     $params = array('refresh_token' => $refresh_token);
     // get access token; todo: move to function
     $response = $this->Client->getAccessToken(self::TOKEN_ENDPOINT, 'refresh_token', $params);
     if ($response['code'] == 200) {
         $this->Client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
         $this->Client->setAccessToken($response['result']['access_token']);
         $this->ready = true;
     }
 }
コード例 #6
0
ファイル: ToolsGoogle.php プロジェクト: JodiWarren/hms
 /**
  * Returns an array containing the access and refresh tokens.
  * We will already be authenticated and authorised by this point
  * Will look something like:
  * {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
  *  "expires_in":3600,"id_token":"TOKEN", "created":1320790426}
  * 
  * @return array token information
  */
 public function getAccessToken()
 {
     $token = json_decode($this->__client->getAccessToken(), true);
     if (!isset($token['refresh_token'])) {
         $token['refresh_token'] = $this->__getRefreshToken();
     }
     return $token;
 }
コード例 #7
0
 /**
  * Constructor
  *
  * @param string $refresh_token Saved token for specified user
  * @return void
  */
 public function __construct($refresh_token)
 {
     if (empty($refresh_token) || !Configure::read('LilTasks.googleApiClientId') || !Configure::read('LilTasks.googleApiClientSecret')) {
         throw new Exception("Cannot init OAuth Api. Missing token, client id or client secret.");
         return;
     }
     $this->Client = new OAuth2\Client(Configure::read('LilTasks.googleApiClientId'), Configure::read('LilTasks.googleApiClientSecret'));
     $params = array('refresh_token' => $refresh_token);
     // get access token; todo: move to function
     $response = $this->Client->getAccessToken(self::TOKEN_ENDPOINT, 'refresh_token', $params);
     if ($response['code'] == 200) {
         $this->Client->setAccessTokenType(OAuth2\Client::ACCESS_TOKEN_BEARER);
         $this->Client->setAccessToken($response['result']['access_token']);
         $this->ready = true;
     } else {
         debug($response);
     }
 }
コード例 #8
0
ファイル: connect.php プロジェクト: Advanture/Online-RolePlay
 /**
  * Completes the connection
  *
  * @access	public
  * @return	redirect
  */
 public function finishConnection()
 {
     if ($_REQUEST['m'] and $_REQUEST['code']) {
         /* Load user */
         $member = IPSMember::load(intval($_REQUEST['m']));
         if ($member['fb_token'] == $_REQUEST['key']) {
             /* Load oAuth */
             require_once IPS_KERNEL_PATH . 'facebook/facebookoauth.php';
             /*noLibHook*/
             $this->_oauth = new FacebookOAuth(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET, FACEBOOK_CALLBACK, $this->extendedPerms);
             /* Load API */
             require_once IPS_KERNEL_PATH . 'facebook/facebook.php';
             /*noLibHook*/
             $this->_api = new Facebook(array('appId' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_SECRET, 'cookie' => true));
             /* Ensure URL is correct */
             $_urlExtra = '';
             if ($_REQUEST['key']) {
                 $_urlExtra .= '&key=' . $_REQUEST['key'];
             }
             if ($_REQUEST['_reg']) {
                 $_urlExtra .= '&_reg=1';
             }
             /* Update callback url */
             $this->_oauth->setCallBackUrl(FACEBOOK_CALLBACK . $_urlExtra);
             /* Generate oAuth token */
             $rToken = $this->_oauth->getAccessToken($_REQUEST['code']);
             if (is_string($rToken)) {
                 try {
                     $_userData = $this->_api->api('me', array('access_token' => $rToken));
                 } catch (Exception $e) {
                     $this->registry->output->logErrorMessage($e->getMessage(), 'FB-EXCEPTION');
                 }
                 /* Ensure user's row is up to date */
                 IPSMember::save($member['member_id'], array('core' => array('fb_uid' => $_userData['id'], 'fb_token' => $rToken)));
             }
         }
     }
     /* Redirect back to settings page */
     $this->registry->getClass('output')->silentRedirect($this->settings['base_url'] . 'app=core&module=usercp&tab=core&area=facebook');
 }
コード例 #9
0
ファイル: connect.php プロジェクト: Advanture/Online-RolePlay
 /**
  * Completes the connection
  *
  * @access	public
  * @return	redirect
  */
 public function finishConnection()
 {
     if ($_REQUEST['m'] and $_REQUEST['oauth_token']) {
         /* Load user */
         $member = IPSMember::load(intval($_REQUEST['m']));
         if ($member['twitter_token'] == $_REQUEST['oauth_token']) {
             /* Reset api to ensure user is not logged in */
             require_once IPS_KERNEL_PATH . 'twitter/twitteroauth.php';
             /*noLibHook*/
             $this->_api = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $member['twitter_token'], $member['twitter_secret']);
             /* Generate oAuth token */
             $rToken = $this->_api->getAccessToken($_REQUEST['oauth_verifier']);
             if ($rToken['oauth_token'] and $rToken['oauth_token_secret']) {
                 $_userData = $this->_api->get('account/verify_credentials');
                 /* Ensure user's row is up to date */
                 IPSMember::save($member['member_id'], array('core' => array('twitter_id' => $_userData['id'], 'twitter_token' => $rToken['oauth_token'], 'twitter_secret' => $rToken['oauth_token_secret'])));
             }
         }
     }
     /* Redirect back to settings page */
     $this->registry->getClass('output')->silentRedirect($this->settings['base_url'] . 'app=core&module=usercp&tab=core&area=twitter');
 }
コード例 #10
0
 /**
  * Open file and return file pointer.
  *
  * @param string $path  file path
  * @param bool   $write open file for writing
  *
  * @return resource|false
  *
  * @author Dmitry (dio) Levashov
  **/
 protected function _fopen($path, $mode = 'rb')
 {
     if ($mode === 'rb' || $mode === 'r') {
         if ($file = $this->_gd_getFile($path)) {
             if ($dlurl = $this->_gd_getDownloadUrl($file)) {
                 $token = $this->client->getAccessToken();
                 $access_token = '';
                 if (is_array($token)) {
                     $access_token = $token['access_token'];
                 } else {
                     if ($token = json_decode($client->getAccessToken())) {
                         $access_token = $token->access_token;
                     }
                 }
                 if ($access_token) {
                     $data = array('target' => $dlurl, 'headers' => array('Authorization: Bearer ' . $access_token));
                     return elFinder::getStreamByUrl($data);
                 }
             }
         }
     }
     return false;
 }
コード例 #11
0
ファイル: connect.php プロジェクト: Advanture/Online-RolePlay
 /**
  * Completes the connection
  *
  * @access	public
  * @return	redirect
  */
 public function finishConnection()
 {
     if ($_REQUEST['m'] and $_REQUEST['key']) {
         /* Load user */
         $member = IPSMember::load(intval($_REQUEST['m']));
         if ($member['vk_token'] == $_REQUEST['key']) {
             /* Reset api to ensure user is not logged in */
             $this->resetApi();
             /* Ensure URL is correct */
             $_urlExtra = '';
             if ($_REQUEST['key']) {
                 $_urlExtra .= '&key=' . $_REQUEST['key'];
             }
             if ($_REQUEST['reg']) {
                 $_urlExtra .= '&reg=1';
             }
             /* Update callback url */
             $this->_api->setVariable('authorize_callback_uri', VKONTAKTE_CALLBACK . $_urlExtra);
             /* Generate oAuth token */
             $rToken = $this->_api->getAccessToken();
             if (is_string($rToken)) {
                 try {
                     $oAuthSession = $this->_api->getSession();
                     $r = $this->_api->api('getProfiles', 'GET', array('uids' => $oAuthSession['user_id'], 'fields' => 'uid'));
                     $_userData = array_pop($r['response']);
                 } catch (Exception $e) {
                     $this->registry->output->logErrorMessage($e->getMessage(), 'VK-EXCEPTION');
                 }
                 /* Ensure user's row is up to date */
                 IPSMember::save($member['member_id'], array('core' => array('vk_uid' => $_userData['uid'], 'vk_token' => $rToken)));
             }
         }
     }
     /* Redirect back to settings page */
     $this->registry->getClass('output')->silentRedirect($this->settings['base_url'] . 'app=core&module=usercp&tab=core&area=vkontakte');
 }
コード例 #12
0
 public static function getAccessToken($code)
 {
     self::$handler->getAccessToken($code);
 }
コード例 #13
0
ファイル: Weixin.php プロジェクト: im286er/Weixin-3
 /**
  * 创建SDK实例,并返回唯一的实例
  * 
  * @param string $token   Token
  * @param string $appid   AppId (服务号必填)
  * @param string $secret  AppSecret (服务号必填)
  * @param boolean $isService 是否是服务号
  * @return Weixin
  */
 public static function init($token, $appid = null, $secret = null, $isService = FALSE)
 {
     if (!isset(self::$instance)) {
         self::instance();
     }
     self::$instance->token = $token;
     self::$instance->isService = $isService;
     if ($appid && $secret) {
         self::$instance->appid = $appid;
         self::$instance->secret = $secret;
         self::$instance->accessToken = self::$instance->getAccessToken();
         if (!self::$instance->accessToken) {
             self::$instance->isService = FALSE;
         }
     }
     return self::$instance;
 }
コード例 #14
0
ファイル: cfacebook.php プロジェクト: ralaxraja/phlypheonix
 /**
  * 
  * Below here will be all Facebook Object wrapped elements
  * 
  */
 public function FB_apiTokened($urlPart)
 {
     $token = $this->facebook->getAccessToken();
     $urlPart .= '?token=' . $token;
     return $this->facebook->api($urlPart);
 }
コード例 #15
0
ファイル: GoogleClient.php プロジェクト: Thyoity/phalcon-rest
 /**
  * Get the Access Token.
  *
  * @return string
  */
 public function getAccessToken()
 {
     return $this->client->getAccessToken();
 }