- Edited
Hi everyone and hello,
I am new to this forum and i try to integrate authentification process with textpattern CMS, i know php and work regularly with Textpattern CMS, but i am strugling with Flarum API right now and need some help if possible.
I installed Flarum on a subdirectory and tryed to make a call using php curl but i got this response
string(56) "{"errors":[{"status":"401","code":"not_authenticated"}]}"
I created a Token on the api_keys table and below is the code i tryed:
<?php
$url = "https://myurl/flarum/api/token";
$headr1 = array();
$headr1[] = 'Content-length: 0';
$headr1[] = 'Content-type: application/json';
$headr1[] = 'Authorization: Token mytokenxxxxxx; userId=1';
$curl = curl_init();
curl_setopt($crl, CURLOPT_HTTPHEADER, $headr1);
curl_setopt($curl, CURLOPT_POST, true);
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "someusernam:hispwd");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if ($rest === false)
{
print_r('Curl error: ' . curl_error($crl));
}
curl_close($curl);
var_dump($result);
?>
Is my code wrong ?
Thanks in advance,