• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Token\StdOAuth2Token类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中OAuth\OAuth2\Token\StdOAuth2Token的典型用法代码示例。如果您正苦于以下问题:PHP StdOAuth2Token类的具体用法?PHP StdOAuth2Token怎么用?PHP StdOAuth2Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: parseAccessTokenResponse

 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     $data = json_decode($responseBody, true);
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     // Salesforce access tokens depend on the session timeout settings.
     // The session timeout for an access token can be configured in Salesforce from Setup by clicking Security Controls | Session Settings.
     $token->setEndOfLife(StdOAuth2Token::EOL_UNKNOWN);
     unset($data['access_token']);
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         // Save Refresh Token persistently until it is cleared manually
         update_option('gf_salesforce_refreshtoken', $data['refresh_token']);
         unset($data['refresh_token']);
     } else {
         $refresh_token = get_option('gf_salesforce_refreshtoken');
         if (!empty($refresh_token)) {
             $token->setRefreshToken($refresh_token);
         }
     }
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:AgilData,项目名称:WordPress-Skeleton,代码行数:31,代码来源:Salesforce.php


示例2: parseAccessTokenResponse

 protected function parseAccessTokenResponse($responseBody)
 {
     $data = json_decode($responseBody, true);
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     return $token;
 }
开发者ID:worldskills,项目名称:concrete5-worldskills,代码行数:12,代码来源:Service.php


示例3: setBaseApiUri

 /**
  * Set the right base endpoint.
  * 
  * @param StdOAuth2Token $token
  */
 protected function setBaseApiUri(StdOAuth2Token $token)
 {
     // Make request uri.
     $endpoint = 'https://login.mailchimp.com/oauth2/metadata?oauth_token=' . $token->getAccessToken();
     // Grab meta data about the token.
     $response = $this->httpClient->retrieveResponse(new Uri($endpoint), array(), array(), 'GET');
     // Parse JSON.
     $meta = json_decode($response, true);
     // Set base api uri.
     $this->baseApiUri = new Uri('https://' . $meta['dc'] . '.api.mailchimp.com/2.0/');
     // Allow chaining.
     return $this;
 }
开发者ID:vladvoth,项目名称:productclash,代码行数:18,代码来源:Mailchimp.php


示例4: __construct

 /**
  * @param array $config
  *
  * param example:
  *
  * private $config = [
  *   'app_key' => 'APP KEY',
  *   'app_secret' => 'APP SECRET',
  *   'access_token' => 'USER TOKEN'
  * ];
  *
  */
 public function __construct($config)
 {
     $serviceFactory = new \OAuth\ServiceFactory();
     $serviceFactory->setHttpClient(new CurlClient());
     $token = new StdOAuth2Token();
     $token->setAccessToken($config['access_token']);
     $storage = new Session();
     $storage->storeAccessToken('linkedin', $token);
     $redirectUrl = '';
     if (isset($_SERVER['HTTP_HOST'])) {
         $redirectUrl = $_SERVER['HTTP_HOST'];
     }
     $credentials = new Credentials($config['app_key'], $config['app_secret'], $redirectUrl);
     $this->service = $serviceFactory->createService('linkedin', $credentials, $storage, ['r_fullprofile', 'r_emailaddress', 'rw_nus']);
 }
开发者ID:vegas-cmf,项目名称:social,代码行数:27,代码来源:Service.php


示例5: parseAccessTokenResponse

 protected function parseAccessTokenResponse($responseBody)
 {
     $data = json_decode($responseBody, true);
     if ($data === null || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
     unset($data['access_token']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:nukeplus,项目名称:nuke,代码行数:15,代码来源:Buffer.php


示例6: arrayToToken

 /**
  * Create token object from array.
  *
  * @param array $data
  * @return TokenInterface
  */
 public function arrayToToken(array $data)
 {
     if ($data && array_key_exists('accessToken', $data) && array_key_exists('accessTokenSecret', $data) && array_key_exists('requestToken', $data) && array_key_exists('requestTokenSecret', $data) && array_key_exists('endOfLife', $data) && array_key_exists('extraParams', $data)) {
         $token = new StdOAuth1Token($data['accessToken']);
         $token->setAccessTokenSecret($data['accessTokenSecret']);
         $token->setRequestToken($data['requestToken']);
         $token->setRequestTokenSecret($data['requestTokenSecret']);
         $token->setEndOfLife($data['endOfLife']);
         $token->setExtraParams($data['extraParams']);
     } elseif ($data && array_key_exists('accessToken', $data) && array_key_exists('refreshToken', $data) && array_key_exists('endOfLife', $data) && array_key_exists('extraParams', $data)) {
         $token = new StdOAuth2Token($data['accessToken'], $data['refreshToken'], null, $data['extraParams']);
         $token->setEndOfLife($data['endOfLife']);
     }
     if (!isset($token) || !$token) {
         return null;
     }
     return $token;
 }
开发者ID:richholt,项目名称:dripsplat,代码行数:24,代码来源:OAuthHelper.php


示例7: parseAccessTokenResponse

 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     $data = json_decode($responseBody, true);
     if (is_null($data) || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     $token->setLifetime(0);
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         unset($data['refresh_token']);
     }
     unset($data['access_token']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:artis-mosties,项目名称:oauth-php,代码行数:22,代码来源:Pinterest.php


示例8: event

 public function event(Request $request, $id)
 {
     $user = User::find($id);
     $cache_key = 'event' . $user->id;
     $response = Cache::get($cache_key);
     if (!$response) {
         if (!$user->google_access_token) {
             return ['status' => 'no_token'];
         }
         $googleService = \OAuth::consumer('Google');
         $storage = $googleService->getStorage();
         $token = new StdOAuth2Token();
         $token->setAccessToken($user->google_access_token);
         $storage->storeAccessToken('Google', $token);
         $resultRaw = json_decode($googleService->request('https://www.googleapis.com/calendar/v3/calendars/primary/events?orderBy=startTime&singleEvents=true&timeMin=' . urlencode(date("Y-m-d\\TH:i:sP"))), true);
         $response = ['status' => 'ok', 'name' => $resultRaw['items'][0]['summary'], 'location' => $resultRaw['items'][0]['location'], 'start' => date("F j, g:i a", strtotime($resultRaw['items'][0]['start']['dateTime'])), 'end' => date("F j, g:i a", strtotime($resultRaw['items'][0]['end']['dateTime']))];
         Cache::put($cache_key, $response, 90);
     }
     return $response;
 }
开发者ID:viorelsfetea,项目名称:SmartMirror,代码行数:20,代码来源:OtherController.php


示例9: parseAccessTokenResponse

 /**
  * Parses the access token response and returns a TokenInterface.
  *
  *
  * @param string $responseBody
  *
  * @return TokenInterface
  *
  * @throws TokenResponseException
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     $request = \Request::getInstance();
     if ($request->get('error')) {
         $reason = $request->get('error_description');
         throw new TokenResponseException($reason);
     }
     $data = json_decode($responseBody, true);
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     $token->setLifetime($data['expires_in']);
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         unset($data['refresh_token']);
     }
     unset($data['access_token']);
     unset($data['expires_in']);
     $data['state'] = $request->get('state');
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:36,代码来源:Community.php


示例10: parseAccessTokenResponse

 protected function parseAccessTokenResponse($responseBody)
 {
     if (version_compare($this->apiVersion, 'v2.2', '>') === true) {
         $data = json_decode($responseBody, true);
     } else {
         parse_str($responseBody, $data);
     }
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         if (is_array($data['error']) === true) {
             $errorMessage = $data['error']['message'];
         } else {
             $errorMessage = $data['error'];
         }
         throw new TokenResponseException('Error in retrieving token: "' . $errorMessage . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     if (isset($data['expires'])) {
         $token->setLifeTime($data['expires']);
     }
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         unset($data['refresh_token']);
     }
     unset($data['access_token']);
     unset($data['expires']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:recca0120,项目名称:socialite,代码行数:31,代码来源:Facebook.php


示例11: refreshAccessToken

 public function refreshAccessToken()
 {
     $access_token = $this->access_token;
     $service = Facades\Social::service($this->provider);
     if (2 === Facades\Social::oauthSpec($this->provider)) {
         $token = new StdOAuth2Token();
         $token->setAccessToken(array_get($access_token, 'token'));
         $token->setRefreshToken(array_get($access_token, 'refresh_token'));
     } else {
         $token = new StdOAuth1Token();
         $token->setAccessToken(array_get($access_token, 'token'));
         $token->setAccessTokenSecret(array_get($access_token, 'secret'));
         $token->setRefreshToken(array_get($access_token, 'refresh_token'));
     }
     $service->getStorage()->storeAccessToken(ucfirst($this->provider), $token);
     try {
         $new_token = $service->refreshAccessToken($token);
     } catch (\Exception $e) {
         return false;
     }
     if (!$new_token->getAccessToken()) {
         return false;
     }
     $access_token['token'] = $new_token->getAccessToken();
     if ($new_token->getEndOfLife()) {
         $access_token['end_of_life'] = $new_token->getEndOfLife();
     }
     if ($new_token->getExtraParams()) {
         $access_token['extra_params'] = $new_token->getExtraParams();
     }
     if (2 !== Facades\Social::oauthSpec($this->provider) && $new_token->getAccessTokenSecret()) {
         $access_token['secret'] = $new_token->getAccessTokenSecret();
     }
     $this->access_token = $access_token;
     $this->save();
     return true;
 }
开发者ID:mmanos,项目名称:laravel-social,代码行数:37,代码来源:Provider.php


示例12: parseAccessTokenResponse

 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     $data = json_decode($responseBody, true);
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error_description']) || isset($data['error'])) {
         throw new TokenResponseException(sprintf('Error in retrieving token: "%s"', isset($data['error_description']) ? $data['error_description'] : $data['error']));
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     $token->setLifeTime($data['expires_in']);
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         unset($data['refresh_token']);
     }
     unset($data['access_token']);
     unset($data['expires_in']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:vladvoth,项目名称:productclash,代码行数:23,代码来源:Dailymotion.php


示例13: parseAccessTokenResponse

 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     // Facebook gives us a query string ... Oh wait. JSON is too simple, understand ?
     parse_str($responseBody, $data);
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     $token->setLifeTime($data['expires']);
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         unset($data['refresh_token']);
     }
     unset($data['access_token']);
     unset($data['expires']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:carriercomm,项目名称:sticky-notes,代码行数:24,代码来源:Facebook.php


示例14: parseAccessTokenResponse

 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     $JSON = new \JSON(JSON_LOOSE_TYPE);
     $data = $JSON->decode($responseBody);
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     if (isset($data['expires'])) {
         $token->setLifeTime($data['expires']);
     }
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         unset($data['refresh_token']);
     }
     unset($data['access_token']);
     unset($data['expires']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:araname,项目名称:dokuwiki-plugin-oauth,代码行数:26,代码来源:Auth0.php


示例15: Credentials

<?php

use OAuth\Common\Consumer\Credentials;
use OAuth\OAuth2\Token\StdOAuth2Token;
require_once __DIR__ . '/../bootstrap.php';
$credentials = new Credentials($githubCredentials['key'], $githubCredentials['secret'], 'http://github.com');
$github = $serviceFactory->createService('GitHub', $credentials, $storage, array());
$token = new StdOAuth2Token();
$token->setAccessToken($githubCredentials['cli_token']);
$token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
$storage->storeAccessToken('GitHub', $token);
$stmt = $dbConnection->query('SELECT id, feed_id, repository FROM feeds_repositories ORDER BY id ASC');
$repositories = [];
$feeds = $stmt->fetchAll();
foreach ($feeds as $repository) {
    $repositories[] = $repository['repository'];
}
$repositories = array_unique($repositories);
$result = [];
foreach ($repositories as $repository) {
    $result[$repository] = json_decode($github->request('repos/' . $repository . '/releases'), true);
}
foreach ($feeds as $feed) {
    $timestamp = new \DateTime();
    foreach ($result[$feed['repository']] as $release) {
        if (postExists($dbConnection, $feed['feed_id'], $release['id'])) {
            continue;
        }
        $postId = addPost($dbConnection, $feed['id'], $release);
        logAddition($dbConnection, $feed['feed_id'], $postId, $timestamp);
    }
开发者ID:dietervds12,项目名称:Feedr,代码行数:31,代码来源:retrieve-releases.php


示例16: getToken

 /**
  * Get token from storage
  *
  * @param  string $provider
  * @param  int $key
  * @return Token
  */
 public function getToken($provider, $key)
 {
     $provider = ucfirst(strtolower($provider));
     $data = $this['option']->get('oauth:token:' . $provider . ':' . $key);
     if ($data && array_key_exists('accessToken', $data) && array_key_exists('accessTokenSecret', $data) && array_key_exists('requestToken', $data) && array_key_exists('requestTokenSecret', $data) && array_key_exists('endOfLife', $data) && array_key_exists('extraParams', $data)) {
         $token = new StdOAuth1Token($data['accessToken']);
         $token->setAccessTokenSecret($data['accessTokenSecret']);
         $token->setRequestToken($data['requestToken']);
         $token->setRequestTokenSecret($data['requestTokenSecret']);
         $token->setEndOfLife($data['endOfLife']);
         $token->setExtraParams($data['extraParams']);
     } elseif ($data && array_key_exists('accessToken', $data) && array_key_exists('refreshToken', $data) && array_key_exists('endOfLife', $data) && array_key_exists('extraParams', $data)) {
         $token = new StdOAuth2Token($data['accessToken'], $data['refreshToken'], null, $data['extraParams']);
         $token->setEndOfLife($data['endOfLife']);
     }
     if (!isset($token) || !$token) {
         return null;
     }
     return $token;
 }
开发者ID:enyaku,项目名称:myGoogleMapsApiV3Test,代码行数:27,代码来源:OAuthHelper.php


示例17: parseAccessTokenResponse

 /**
  * @param string $responseBody
  * @return StdOAuth2Token
  * @throws TokenResponseException
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     $data = $this->service->parseAccessTokenResponse($responseBody);
     if (!isset($data) || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     }
     $error = $this->service->getAccessTokenResponseError($data);
     if (isset($error)) {
         throw new TokenResponseException('Error in retrieving token: "' . $error . '"');
     }
     $token = new StdOAuth2Token();
     $names = $this->service->getAccessTokenArgumentNames();
     $token->setAccessToken($data[$names['access_token']]);
     unset($data[$names['access_token']]);
     if (isset($data[$names['expires_in']])) {
         $token->setLifeTime($data[$names['expires_in']]);
         unset($data[$names['expires_in']]);
     } else {
         $token->setLifetime($this->service->getTokenDefaultLifetime());
     }
     if (isset($data[$names['refresh_token']])) {
         $token->setRefreshToken($data[$names['refresh_token']]);
         unset($data[$names['refresh_token']]);
     }
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:barbq,项目名称:yii2eauth,代码行数:32,代码来源:ServiceProxy.php


示例18: parseAccessTokenResponse

 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     parse_str($responseBody, $data);
     if (null === $data || !is_array($data) || empty($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     } elseif (isset($data['error_reason'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error_reason'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     $token->setLifeTime($data['expires']);
     // I hope one day Deezer add a refresh token :)
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         unset($data['refresh_token']);
     }
     unset($data['access_token']);
     unset($data['expires']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:DevSlashNull,项目名称:PHPoAuthLib,代码行数:26,代码来源:Deezer.php


示例19: parseAccessTokenResponse

 /**
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     $data = @json_decode($responseBody, true);
     // Facebook gives us a query string on old api (v2.0)
     if (!$data) {
         parse_str($responseBody, $data);
     }
     if (null === $data || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
     }
     $token = new StdOAuth2Token();
     $token->setAccessToken($data['access_token']);
     if (isset($data['expires'])) {
         $token->setLifeTime($data['expires']);
     }
     if (isset($data['refresh_token'])) {
         $token->setRefreshToken($data['refresh_token']);
         unset($data['refresh_token']);
     }
     unset($data['access_token']);
     unset($data['expires']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:RewardGateway,项目名称:PHPoAuthLib,代码行数:29,代码来源:Facebook.php


示例20: parseAccessTokenResponse

 /** -----------------------------------------------------------------------
  * {@inheritdoc}
  */
 protected function parseAccessTokenResponse($responseBody)
 {
     $data = json_decode($responseBody, true);
     if ($data === null || !is_array($data)) {
         throw new TokenResponseException('Unable to parse response.');
     } elseif (isset($data['error'])) {
         $err = $data['error'];
         throw new TokenResponseException("Error in retrieving token: \"{$err}\"");
     }
     $token = new StdOAuth2Token($data['access_token'], null, $data['expires_in']);
     unset($data['access_token']);
     unset($data['expires_in']);
     $token->setExtraParams($data);
     return $token;
 }
开发者ID:RewardGateway,项目名称:PHPoAuthLib,代码行数:18,代码来源:BattleNet.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP OAuth2\RequestInterface类代码示例发布时间:2022-05-23
下一篇:
PHP Service\AbstractService类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap