Skip to content

Instantly share code, notes, and snippets.

@thiphariel
Created August 31, 2015 13:46
Show Gist options
  • Select an option

  • Save thiphariel/6e44dfaa60114af05836 to your computer and use it in GitHub Desktop.

Select an option

Save thiphariel/6e44dfaa60114af05836 to your computer and use it in GitHub Desktop.
Retrieve ghost authentification token in PHP
<?php
// Fill the informations below with your own credentials
$domain = 'http://my-domain.com';
$data = array(
'grant_type' => "password",
'username' => "[MY_MAIL_ADDRESS]",
'password' => "[MY_PASSWORD]",
'client_id' => "ghost-admin"
);
// Create map with request parameters
// Build Http query using params
$query = http_build_query($data);
// Create context resource for our request
$context = stream_context_create (array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $query
)
));
// Read page rendered as result of your POST request
$result = file_get_contents(
$domain . '/ghost/api/v0.1/authentication/token',
false,
$context
);
header("Content-type: application/json");
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment