本文整理汇总了PHP中OAuth\OAuth2\Token\StdOAuth2Token类的典型用法代码示例。如果您正苦于以下问题:PHP StdOAuth2Token类的具体用法?PHP StdOAuth2Token怎么用?PHP StdOAuth2Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StdOAuth2Token类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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']);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}