public function send(Provider $provider, $userId, $requestScope, Request $request)
    {
        $accessToken = $this->getAccessToken($provider, $userId, $requestScope);
        if (false === $accessToken) {
            return false;
        }

        if ($accessToken->isExpired($this->dateTime)) {
            // access_token is expired, try to refresh it
            if (null === $accessToken->getRefreshToken()) {
                // we do not have a refresh_token, delete this access token, it
                // is useless now...
                $this->tokenStorage->deleteAccessToken($userId, $accessToken);

                return false;
            }

            // try to refresh the AccessToken
            $accessToken = $this->refreshAccessToken($provider, $userId, $accessToken);
            if (false === $accessToken) {
                // didn't work
                return false;
            }
        }

        // add Authorization header to the request headers
        $request->setHeader('Authorization', \sprintf('Bearer %s', $accessToken->getToken()));

        $response = $this->httpClient->send($request);
        if (401 === $response->getStatusCode()) {
            // the access_token was not accepted, but isn't expired, we assume
            // the user revoked it, also no need to try with refresh_token
            $this->tokenStorage->deleteAccessToken($userId, $accessToken);

            return false;
        }

        return $response;
    }
public function send(Provider $provider, $userId, $requestScope, Request $request)
    {
        $accessToken = $this->getAccessToken($provider, $userId, $requestScope);
        if (false === $accessToken) {
            return false;
        }

        if ($accessToken->isExpired($this->dateTime)) {
            // access_token is expired, try to refresh it
            if (null === $accessToken->getRefreshToken()) {
                // we do not have a refresh_token, delete this access token, it
                // is useless now...
                $this->tokenStorage->deleteAccessToken($userId, $accessToken);

                return false;
            }

            // try to refresh the AccessToken
            $accessToken = $this->refreshAccessToken($provider, $userId, $accessToken);
            if (false === $accessToken) {
                // didn't work
                return false;
            }
        }

        // add Authorization header to the request headers
        $request->setHeader('Authorization', \sprintf('Bearer %s', $accessToken->getToken()));

        $response = $this->httpClient->send($request);
        if (401 === $response->getStatusCode()) {
            // the access_token was not accepted, but isn't expired, we assume
            // the user revoked it, also no need to try with refresh_token
            $this->tokenStorage->deleteAccessToken($userId, $accessToken);

            return false;
        }

        return $response;
    }
public function send ( Provider $ provider , $ userId , $ requestScope , Request $ request ) { $ accessToken = $ this -> getAccessToken ( $ provider , $ userId , $ requestScope ) ; if ( false === $ accessToken ) { return false ; } if ( $ accessToken -> isExpired ( $ this -> dateTime ) ) { // access_token is expired, try to refresh it if ( null === $ accessToken -> getRefreshToken ( ) ) { // we do not have a refresh_token, delete this access token, it // is useless now... $ this -> tokenStorage -> deleteAccessToken ( $ userId , $ accessToken ) ; return false ; } // try to refresh the AccessToken $ accessToken = $ this -> refreshAccessToken ( $ provider , $ userId , $ accessToken ) ; if ( false === $ accessToken ) { // didn't work return false ; } } // add Authorization header to the request headers $ request -> setHeader ( 'Authorization' , \ sprintf ( 'Bearer %s' , $ accessToken -> getToken ( ) ) ) ; $ response = $ this -> httpClient -> send ( $ request ) ; if ( 401 === $ response -> getStatusCode ( ) ) { // the access_token was not accepted, but isn't expired, we assume // the user revoked it, also no need to try with refresh_token $ this -> tokenStorage -> deleteAccessToken ( $ userId , $ accessToken ) ; return false ; } return $ response ; }
Perform a HTTP request.

@param Provider     $provider
@param string       $userId
@param string       $requestScope
@param Http\Request $request

@return false|Http\Response
Perform a HTTP request .