I am trying to figure out why my code wont work.
Current codebase:
function initAPI(){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "URL"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "FIELDS"); $headers = array(); $headers[] = 'Content-Type: application/x-www-form-urlencoded'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); return $result; } $init_api_res = json_decode(initAPI()); $access_token = $init_api_res->access_token; //print_r("[DEBUG] JWT: ".$access_token); //Outputting correct JWT function bankIdVerify() { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "URL"); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Authorization: Bearer '. $access_token, 'Content-Type: application/json')); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $data = <<<DATA { //i have removed this data for safety reason also it is not relevant. } DATA; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $resp = curl_exec($curl); curl_close($curl); return $resp; } print_r(bankIdVerify());
The result of the commented print_r are:
[DEBUG] JWT: eyJhbGciOiJSUzI1NiIsImtpZCI6InNhbmRib3gtc2lnbmluZy1rZXktN2ViNmZkNjhiMTk5YjA0M2FlY2I1ZGRjMzI0ZWYwZmQiLCJ0eXAiOiJhdCtqd3QifQ.eyJpc3MiOiJodHRwczovL2FwaS5zaWduaWNhdC5jb20vYXV0aC9vcGVuIiwibmJmIjoxNzA2ODc5MDEzLCJpYXQiOjE3MDY4NzkwMTMsImV4cCI6MTcwNjg3OTYxMywiYXVkIjoiaHR0cHM6Ly9hcGkuc2lnbmljYXQuY29tIiwic2NvcGUiOlsic2lnbmljYXQtYXBpIl0sImNsaWVudF9pZCI6InNhbmRib3gtZ3JpdHR5LWJ1Y2tldC04MTYiLCJhY2NvdW50X2lkIjoiYS1zcGdlLXI5eGpUV29nbk5adlJLSzJ6bW83Iiwic2FuZGJveCI6dHJ1ZSwianRpIjoiNDYyNzg4RDlBM0VEOTMzQTZBQjhFMEI0RDExQTgzMjQifQ.picqUqyxNppiYf6NQncxE2qsWJWS7-Ls8EPhQZGbiqJIP7Rr8RUPQTdKieRxjx_A1OZj6MfR885kAYSHxFrFvsqsFdouYZ0HdeS1USXpLw9aZn9ozZOpN7O8F4wIfZDjVQ0saDNHu7QQJC9q6f5C3gtXaMxzifJ8fc2Cv69CFgiyft1fCozvmvhjxuu61ZwgL6lAbNeS5dS4df7Yc4Wmxlj-pLDhHpmuVg_mK9c4lPMKik-qp6i3MsYbSBUkPGG8lUhO4vsnfFkIjh5UnwarVShasgO6g7CcvwNpz82zjrZyHFp7gXN0H7DbX11W5Xe4QQijjDEtf7Qccoji2r-gfA
I am getting the error:{"status":401,"code":"token_invalid_not_a_jwt","title":"The provided bearer token is not a valid JWT","detail":"","traceId":"nHR4NMjtZ2lusq8bQRqNPlTF2CdQ2"}
The JWT Token assigned to $access_token is correct and valid.
When i try to send a POST request with postman i am getting valid response. What am i doing wrong, or missing here?
Can't seem to figure it out on my own.