src/Client.php
public function obtainAccessToken($clientSecret, $code)
    {
        if (null === $this->_state->redirect_uri) {
            throw new \Exception(
                'The state\'s redirect URI must be set to call'
                    . ' obtainAccessToken()'
            );
        }

        $values = [
            'client_id'     => $this->clientId,
            'redirect_uri'  => $this->_state->redirect_uri,
            'client_secret' => (string) $clientSecret,
            'code'          => (string) $code,
            'grant_type'    => 'authorization_code',
        ];

        $response = $this->httpClient->post(
            self::TOKEN_URL,
            ['form_params' => $values]
        );

        $body = $response->getBody();
        $data = json_decode($body);

        if ($data === null) {
            throw new \Exception('json_decode() failed');
        }

        $this->_state->redirect_uri = null;

        $this->_state->token = (object) [
            'obtained' => time(),
            'data'     => $data,
        ];

        $this->graph->setAccessToken($this->_state->token->data->access_token);
    }
public function obtainAccessToken($clientSecret, $code)
    {
        if (null === $this->_state->redirect_uri) {
            throw new \Exception(
                'The state\'s redirect URI must be set to call'
                    . ' obtainAccessToken()'
            );
        }

        $values = [
            'client_id'     => $this->clientId,
            'redirect_uri'  => $this->_state->redirect_uri,
            'client_secret' => (string) $clientSecret,
            'code'          => (string) $code,
            'grant_type'    => 'authorization_code',
        ];

        $response = $this->httpClient->post(
            self::TOKEN_URL,
            ['form_params' => $values]
        );

        $body = $response->getBody();
        $data = json_decode($body);

        if ($data === null) {
            throw new \Exception('json_decode() failed');
        }

        $this->_state->redirect_uri = null;

        $this->_state->token = (object) [
            'obtained' => time(),
            'data'     => $data,
        ];

        $this->graph->setAccessToken($this->_state->token->data->access_token);
    }
public function obtainAccessToken ( $ clientSecret , $ code ) { if ( null === $ this -> _state -> redirect_uri ) { throw new \ Exception ( 'The state\'s redirect URI must be set to call' . ' obtainAccessToken()' ) ; } $ values = [ 'client_id' => $ this -> clientId , 'redirect_uri' => $ this -> _state -> redirect_uri , 'client_secret' => ( string ) $ clientSecret , 'code' => ( string ) $ code , 'grant_type' => 'authorization_code' , ] ; $ response = $ this -> httpClient -> post ( self :: TOKEN_URL , [ 'form_params' => $ values ] ) ; $ body = $ response -> getBody ( ) ; $ data = json_decode ( $ body ) ; if ( $ data === null ) { throw new \ Exception ( 'json_decode() failed' ) ; } $ this -> _state -> redirect_uri = null ; $ this -> _state -> token = ( object ) [ 'obtained' => time ( ) , 'data' => $ data , ] ; $ this -> graph -> setAccessToken ( $ this -> _state -> token -> data -> access_token ) ; }
Obtains a new access token from OAuth. This token is valid for one hour.

@param string $clientSecret
The OneDrive client secret.
@param string $code
The code returned by OneDrive after successful log in.

@throws Exception
Thrown if the redirect URI of this Client instance's state is not
set.
@throws Exception
Thrown if the HTTP response body cannot be JSON-decoded.
Obtains a new access token from OAuth . This token is valid for one hour .