src/AuthorizationAbstract.php
public function refreshToken(AccessToken $accessToken)
    {
        // request data
        $refreshToken = $accessToken->getRefreshToken();
        $scope        = $accessToken->getScope();

        if (empty($refreshToken)) {
            throw new RuntimeException('No refresh token was set');
        }

        $data = array(
            'grant_type'    => 'refresh_token',
            'refresh_token' => $refreshToken,
        );

        if (!empty($scope)) {
            $data['scope'] = $scope;
        }

        // authentication
        $header = array();

        if ($this->type == self::AUTH_BASIC) {
            $header['Authorization'] = 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret);
        }

        if ($this->type == self::AUTH_POST) {
            $data['client_id']     = $this->clientId;
            $data['client_secret'] = $this->clientSecret;
        }

        $request  = new PostRequest($this->url, $header, $data);
        $response = $this->httpClient->request($request);

        $data = Json\Parser::decode($response->getBody());

        if ($response->getStatusCode() == 200) {
            return $this->newToken($data);
        } else {
            throw new RuntimeException('Could not refresh access token');
        }
    }
public function refreshToken(AccessToken $accessToken)
    {
        // request data
        $refreshToken = $accessToken->getRefreshToken();
        $scope        = $accessToken->getScope();

        if (empty($refreshToken)) {
            throw new RuntimeException('No refresh token was set');
        }

        $data = array(
            'grant_type'    => 'refresh_token',
            'refresh_token' => $refreshToken,
        );

        if (!empty($scope)) {
            $data['scope'] = $scope;
        }

        // authentication
        $header = array();

        if ($this->type == self::AUTH_BASIC) {
            $header['Authorization'] = 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret);
        }

        if ($this->type == self::AUTH_POST) {
            $data['client_id']     = $this->clientId;
            $data['client_secret'] = $this->clientSecret;
        }

        $request  = new PostRequest($this->url, $header, $data);
        $response = $this->httpClient->request($request);

        $data = Json\Parser::decode($response->getBody());

        if ($response->getStatusCode() == 200) {
            return $this->newToken($data);
        } else {
            throw new RuntimeException('Could not refresh access token');
        }
    }
public function refreshToken ( AccessToken $ accessToken ) { // request data $ refreshToken = $ accessToken -> getRefreshToken ( ) ; $ scope = $ accessToken -> getScope ( ) ; if ( empty ( $ refreshToken ) ) { throw new RuntimeException ( 'No refresh token was set' ) ; } $ data = array ( 'grant_type' => 'refresh_token' , 'refresh_token' => $ refreshToken , ) ; if ( ! empty ( $ scope ) ) { $ data [ 'scope' ] = $ scope ; } // authentication $ header = array ( ) ; if ( $ this -> type == self :: AUTH_BASIC ) { $ header [ 'Authorization' ] = 'Basic ' . base64_encode ( $ this -> clientId . ':' . $ this -> clientSecret ) ; } if ( $ this -> type == self :: AUTH_POST ) { $ data [ 'client_id' ] = $ this -> clientId ; $ data [ 'client_secret' ] = $ this -> clientSecret ; } $ request = new PostRequest ( $ this -> url , $ header , $ data ) ; $ response = $ this -> httpClient -> request ( $ request ) ; $ data = Json \ Parser :: decode ( $ response -> getBody ( ) ) ; if ( $ response -> getStatusCode ( ) == 200 ) { return $ this -> newToken ( $ data ) ; } else { throw new RuntimeException ( 'Could not refresh access token' ) ; } }
Tries to refresh an access token if an refresh token is available.
Returns the new received access token or throws an excepion

@param \PSX\Oauth2\AccessToken $accessToken
@return \PSX\Oauth2\AccessToken
Tries to refresh an access token if an refresh token is available . Returns the new received access token or throws an excepion