Returns a client found by the access token.

@param string $accessToken

@return ClientInterface
163190
public function findByAccessToken($accessToken)
    {
        if ($accessToken === '') {
            $client = new AnonymousClient();

            $this->clients[$client->getAccessToken()] = $client;

            return $client;
        }

        if (! isset($this->clients[$accessToken])) {

            return null;
        }

        return $this->clients[$accessToken];
    }
179640
private function cacheToken(AccessToken $accessToken)
    {
        $tz = self::TIME_ZONE;
        $kvs = $this->getKeyValueStorage();

        $liveTimeInSec = Carbon::createFromTimestamp($accessToken->getExpires(), $tz)->diffInSeconds(Carbon::now($tz));

        $kvs->set(self::ACCESS_TOKEN_KEY, $accessToken->getToken());
        $kvs->expire(self::ACCESS_TOKEN_KEY, $liveTimeInSec);
        $kvs->set(self::REFRESH_TOKEN_KEY, $accessToken->getRefreshToken());
    }
342971
function refreshToken($accessToken, $sessionHandle) {
		$code = $this->request ( 'GET', $this->url ( 'AccessToken', '' ), array (
				'oauth_token' => $accessToken,
				'oauth_session_handle' => $sessionHandle 
		) );
		if ($this->response ['code'] == 200) {
			
			$response = $this->extract_params ( $this->response ['response'] );
			
			return $response;
		} else {
			$this->response ['helper'] = "TokenFatal";
			return $this->response;
		}
	}
739200
function getClient($clientName)
    {
        if (! isset($this->clients[$clientName]) )
            // if not client constructed look for lazy options:
            $this->clients[$clientName] = $this->_attainClient($clientName);


        return $this->clients[$clientName];
    }
257223
public function setAccessToken($accessToken)
    {
        if (in_array('access_token', $this->persistantMap)) {
            $this->store->set('access_token', $accessToken);
        }

        $this->accessToken = $accessToken;
        return $this;
    }
879638
public function refreshToken($refreshToken)
	{
		$this->result = $this->http->get($this->getUrl('oauth2.0/token', array(
			'grant_type'	=>	'refresh_token',
			'client_id'		=>	$this->appid,
			'client_secret'	=>	$this->appSecret,
			'refresh_token'	=>	$refreshToken,
		)))->jsonp(true);
		return isset($this->result['code']) && 0 == $this->result['code'];
	}
342070
private function getFacebookSession($accessToken)
	{
		$facebookSession = new FacebookSession($accessToken);

		try 
		{
		  $facebookSession->validate();

		  return $facebookSession;
		} 
		catch (FacebookRequestException $ex)
		{
			throw new FacebookException($ex->getMessage());
		}
		catch (\Exception $ex) 
		{
			throw new FacebookException($ex->getMessage());
		}
	}
92737
public function get($token)
    {
        $result = $this->getConnection()->table('oauth_access_tokens')
                ->where('oauth_access_tokens.id', $token)
                ->first();

        if (is_null($result)) {
            return;
        }

        return (new AccessTokenEntity($this->getServer()))
               ->setId($result->id)
               ->setExpireTime((int) $result->expire_time);
    }
725699
public function withAccessToken (AccessToken $token)
    {
        $config = $this->getConfig();
        $this->configureHandlers($config['handler']);
        
        $config['wechat.accessToken'] = $token;
        $config['wechat.developerMode'] = $this->developerMode;
        
        return new static($config);
    }
96092
public function redeemAction($accessToken) {
		if ($this->request->getHttpRequest()->getMethod() !== 'POST') {
			$this->response->setStatus(405);
			$this->response->setHeader('Allow', 'POST');
			return;
		}

		$accessTokenObject = $this->accessTokenRepository->findByIdentifier($accessToken);
		if (!$accessTokenObject instanceof AccessToken) {
			$this->response->setStatus(404);
			$this->view->assign('value', array('message' => 'Invalid access token'));
			return;
		}

		$sessionId = $accessTokenObject->getSessionId();
		$session = $this->sessionManager->getSession($sessionId);
		if (!$this->sessionIsActive($session)) {
			$this->response->setStatus(403);
			$this->view->assign('value', array('message' => 'Session expired'));
			return;
		}

		$this->accessTokenRepository->remove($accessTokenObject);

		// TODO Move the actual logic of redemption to a service

		$ssoClient = $accessTokenObject->getSsoClient();
		$this->singleSignOnSessionManager->registerSsoClient($session, $ssoClient);

		// TODO Get the account from the global session
		// TODO What to do with multiple accounts?
		$account = $accessTokenObject->getAccount();
		$accountData = $this->clientAccountMapper->getAccountData($accessTokenObject->getSsoClient(), $account);

		if ($this->ssoLogger !== NULL) {
			$this->ssoLogger->log('Redeemed access token "' . $accessToken . '" from client "' . $ssoClient->getServiceBaseUri() . '" for session "' . $sessionId . '" and account "' . $account->getAccountIdentifier() . '"', LOG_INFO);
		}

		$this->response->setStatus(201);

		$this->view->assign('value', array(
			'account' => $accountData,
			'sessionId' => $sessionId
		));
	}
719022
public function getClientToken()
    {
        $client = app('db')->connection()->table('clients')
            ->where('client_id', config('services.northstar.client_credentials.client_id'))
            ->first();

        // If any of the required fields are empty, return null.
        if (empty($client->access_token) || empty($client->access_token_expiration)) {
            return null;
        }

        return new AccessToken([
            'access_token' => $client->access_token,
            'expires' => $client->access_token_expiration,
        ]);
    }
1177955
public function getUserInfo($accessToken = null)
	{
		$this->result = $this->http->get($this->getUrl('api/account/current_user', array(
			'access_token'	=>	null === $accessToken ? $this->accessToken : $accessToken,
		)))->json(true);
		if($this->isSuccess($this->result))
		{
			$this->openid = $this->result['data']['global_key'];
			return $this->result;
		}
		else
		{
			throw new ApiException($this->getErrorCode($this->result), $this->getErrorMsg($this->result));
		}
	}
1341873
public function validateAccessToken($headersOnly = true, $accessToken = null)
    {
        return $this->resourceServer->isValidRequest($headersOnly, $accessToken);
    }
1329233
public function setAccessTokenFromParams($accessToken)
    {
        $existingAccessToken = $this->getAccessToken();
        if (!$existingAccessToken) {
            $this->setAccessToken($accessToken);
        } elseif ($accessToken !== $existingAccessToken) {
            throw new SteeinSDKException('Ошибка доступа к токенам. Токен доступа, указанный в запросе SteeinRequest, и токен, указанный в параметрах URL или POST, не совпадают.');
        }

        return $this;
    }
834232
public function getByAccessToken(AccessTokenEntity $accessToken)
    {
        $sql = <<<SQL
SELECT os.id, os.owner_type, os.owner_id, os.client_id, os.client_redirect_uri
FROM oauth_session os
INNER JOIN oauth_access_token oat ON(oat.session_id = os.id)
WHERE oat.access_token = :token
SQL;
        foreach ($this->getDbConnection()->fetchAll($sql, ['token' => $accessToken->getId()]) as $row) {
            if ($row) {
                return (new SessionEntity($this->server))
                    ->setId($row['id'])
                    ->setOwner($row['owner_type'], $row['owner_id']);
            }
        }
        return null;
    }
718644
private function getUser(TokenInterface $authenticationToken)
    {
        $user = $authenticationToken->getUser();

        if (is_string($user)) {
            return $user;
        } elseif (method_exists($user, 'getAPIUser')) {
            return $user->getAPIUser()->id;
        }

        return $authenticationToken->getUsername();
    }
1368047
protected function getAccessTokenWithRefreshToken(RefreshToken $refreshToken){
		// Send post request to authentication service
		$params = array(
			'client_id' => $this->getConfig()->getClientId(),
			'refresh_token' => $refreshToken->getRefreshToken(),
			'grant_type' => 'refresh_token',
		);
		$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/token", $params);
		$output = $response['output'];
		$httpcode = $response['code'];
		
		switch($httpcode){
			case "200" : 
				$responseObject = json_decode($output);
				if(isset($responseObject->error)){
					// an error occured, the RefreshToken is most likely invalid
					// delete RefreshToken to retrieve new one on next request
					$this->getConfig()->getStorage()->deleteRefreshToken();
					return null;
				}
				// create access token and save it
				$accessToken = new AccessToken(new DateTime(), $responseObject->access_token, $responseObject->token_type, $responseObject->expires_in);
				$this->getConfig()->getStorage()->saveAccessToken($accessToken);
				return $accessToken;
		}
		return null;
	}