private function getAccessToken($code)
    {
        $this->logger->debug('Get Access Token.');
        $this->initRequest();
        $token_url = $this->fcBaseUrl.'token';
        $post_data = [
            "grant_type"    => "authorization_code",
            "redirect_uri"  => $this->callbackUrl,
            "client_id"     => $this->clientId,
            "client_secret" => $this->clientSecret,
            "code"          => $code,
        ];
        $this->logger->debug('POST Data to FranceConnect.');
        $this->setPostFields($post_data);
        $response = \Unirest\Request::post($token_url);
        
        // check status code
        if ($response->code != Response::HTTP_OK) {
            $result_array = $response->body;
            $description = array_key_exists(
                "error_description",
                $result_array
            ) ? $result_array["error_description"] : '';
            $this->logger->error(
                $result_array["error"].$description
            );
            throw new Exception("FranceConnectError".$response->code." msg = ".$response->raw_body);
        }
        
        $result_array = $response->body;
        $id_token = $result_array['id_token'];
        $this->session->set(static::ID_TOKEN_HINT, $id_token);
        $all_part = explode(".", $id_token);
        $payload = json_decode(base64_decode($all_part[1]), true);
        
        // check nonce parameter
        if ($payload['nonce'] != $this->session->get(static::OPENID_SESSION_NONCE)) {
            $this->logger->error('The value of the parameter NONCE is not equal to the one which is expected');
            throw new SecurityException("The nonce parameter is invalid");
        }
        // verify the signature of jwt
        $this->logger->debug('Check JWT signature.');
        $jws = SimpleJWS::load($id_token);
        if (!$jws->verify($this->clientSecret)) {
            $this->logger->error('The signature of the JWT is not valid.');
            throw new SecurityException("JWS is invalid");
        }
        
        $this->session->remove(static::OPENID_SESSION_NONCE);
        
        return $result_array['access_token'];
    }
private function getAccessToken($code)
    {
        $this->logger->debug('Get Access Token.');
        $this->initRequest();
        $token_url = $this->fcBaseUrl.'token';
        $post_data = [
            "grant_type"    => "authorization_code",
            "redirect_uri"  => $this->callbackUrl,
            "client_id"     => $this->clientId,
            "client_secret" => $this->clientSecret,
            "code"          => $code,
        ];
        $this->logger->debug('POST Data to FranceConnect.');
        $this->setPostFields($post_data);
        $response = \Unirest\Request::post($token_url);
        
        // check status code
        if ($response->code != Response::HTTP_OK) {
            $result_array = $response->body;
            $description = array_key_exists(
                "error_description",
                $result_array
            ) ? $result_array["error_description"] : '';
            $this->logger->error(
                $result_array["error"].$description
            );
            throw new Exception("FranceConnectError".$response->code." msg = ".$response->raw_body);
        }
        
        $result_array = $response->body;
        $id_token = $result_array['id_token'];
        $this->session->set(static::ID_TOKEN_HINT, $id_token);
        $all_part = explode(".", $id_token);
        $payload = json_decode(base64_decode($all_part[1]), true);
        
        // check nonce parameter
        if ($payload['nonce'] != $this->session->get(static::OPENID_SESSION_NONCE)) {
            $this->logger->error('The value of the parameter NONCE is not equal to the one which is expected');
            throw new SecurityException("The nonce parameter is invalid");
        }
        // verify the signature of jwt
        $this->logger->debug('Check JWT signature.');
        $jws = SimpleJWS::load($id_token);
        if (!$jws->verify($this->clientSecret)) {
            $this->logger->error('The signature of the JWT is not valid.');
            throw new SecurityException("JWS is invalid");
        }
        
        $this->session->remove(static::OPENID_SESSION_NONCE);
        
        return $result_array['access_token'];
    }
private function getAccessToken ( $ code ) { $ this -> logger -> debug ( 'Get Access Token.' ) ; $ this -> initRequest ( ) ; $ token_url = $ this -> fcBaseUrl . 'token' ; $ post_data = [ "grant_type" => "authorization_code" , "redirect_uri" => $ this -> callbackUrl , "client_id" => $ this -> clientId , "client_secret" => $ this -> clientSecret , "code" => $ code , ] ; $ this -> logger -> debug ( 'POST Data to FranceConnect.' ) ; $ this -> setPostFields ( $ post_data ) ; $ response = \ Unirest \ Request :: post ( $ token_url ) ; // check status code if ( $ response -> code != Response :: HTTP_OK ) { $ result_array = $ response -> body ; $ description = array_key_exists ( "error_description" , $ result_array ) ? $ result_array [ "error_description" ] : '' ; $ this -> logger -> error ( $ result_array [ "error" ] . $ description ) ; throw new Exception ( "FranceConnectError" . $ response -> code . " msg = " . $ response -> raw_body ) ; } $ result_array = $ response -> body ; $ id_token = $ result_array [ 'id_token' ] ; $ this -> session -> set ( static :: ID_TOKEN_HINT , $ id_token ) ; $ all_part = explode ( "." , $ id_token ) ; $ payload = json_decode ( base64_decode ( $ all_part [ 1 ] ) , true ) ; // check nonce parameter if ( $ payload [ 'nonce' ] != $ this -> session -> get ( static :: OPENID_SESSION_NONCE ) ) { $ this -> logger -> error ( 'The value of the parameter NONCE is not equal to the one which is expected' ) ; throw new SecurityException ( "The nonce parameter is invalid" ) ; } // verify the signature of jwt $ this -> logger -> debug ( 'Check JWT signature.' ) ; $ jws = SimpleJWS :: load ( $ id_token ) ; if ( ! $ jws -> verify ( $ this -> clientSecret ) ) { $ this -> logger -> error ( 'The signature of the JWT is not valid.' ) ; throw new SecurityException ( "JWS is invalid" ) ; } $ this -> session -> remove ( static :: OPENID_SESSION_NONCE ) ; return $ result_array [ 'access_token' ] ; }
Get Access Token.

@param string $code authorization code

@return string access token
@throws SecurityException
@throws Exception
Get Access Token .