Api on Laravel calling an external API with CURL : "has been blocked by CORS policy"

Viewed 17

I need your help on a problem with one of my APIs. When a user logs into their personal space and goes to their completed orders page, my Nuxt Application calls my Laravel API. This one retrieves the orders in database, and, foreach order, i call an external API (on another domain) to check status.

In my api route:

$ckfile =  @tempNam('/tmp', 'CURLCOOKIE') ;

curl_setopt_array($curl, array(
            CURLOPT_URL => $settings['oneid_base_url'].'/Login',
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_HTTPHEADER => array(
                'Content-Type: application/json',
                'Access-Control-Allow-Origin: *',
                'Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT',
            ),

            CURLOPT_POSTFIELDS =>'{
                "CompanyDB": "'.$company.'",
                "UserName": "'.$username.'",
                "Password": "'.$password.'"
            }',

            CURLOPT_COOKIEJAR =>  $ckfile ,
        ));

But, i have this response of my console:

Access to XMLHttpRequest at '{{api_url}}/api/orders/from/1' from origin '{{app_url}}' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What more can I add than these Headers? Thanks a lot, this is a really blocking problem for my project.

0 Answers
Related