Created
August 31, 2015 13:46
-
-
Save thiphariel/6e44dfaa60114af05836 to your computer and use it in GitHub Desktop.
Retrieve ghost authentification token in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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