-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSRF Token #1
Comments
Hello, I think I have the same problem. I have followed all the steps from this article. The execution of get_resources.php works without any problems! Thank you in advance! |
Do this: $gpgAuth->login();
$ch = curl_init($config['server_url'] . '/users/me.json?api-version=v2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $gpgAuth->getCookie());
$response = curl_exec($ch);
curl_close($ch);
preg_match('/^Set-Cookie:\s*([^;]*)/mi', $response, $matches);
parse_str($matches[1], $csrfCookie);
$csrfToken = $csrfCookie['csrfToken'];
$sessionCookie = $gpgAuth->getCookie();
$ch = curl_init($config['server_url'] . '<your-api-call>?api-version=v2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $gpgAuth->getCookie());
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(<your-data>));
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-CSRF-Token: ' . $csrfToken,
'Accept: application/json',
'Content-Type: application/json',
'Cookie: ' . $sessionCookie
));
$response = curl_exec($ch);
curl_close($ch); this worked yor me. My API calls are now accepted and executed. |
Hello,
could you update your example to work with CSRF cookie?
thanks
The text was updated successfully, but these errors were encountered: