简体   繁体   English

Stormpath Rest API PHP

[英]Stormpath Rest api PHP

can someone help me write this in the form of an httpRequest in php. 有人可以帮助我以php中的httpRequest形式编写此代码。 I´ve tried many times and failed. 我尝试了很多次都失败了。 I don´t know why but I simply can´t get it right. 我不知道为什么,但我做不到。

curl -i --user $YOUR_API_KEY_ID:$YOUR_API_KEY_SECRET \\ ' https://api.stormpath.com/v1/tenants/current ' curl -i-用户$ YOUR_API_KEY_ID:$ YOUR_API_KEY_SECRET \\' https ://api.stormpath.com/v1/tenants/current'

Any help would be greatly appreciated. 任何帮助将不胜感激。

So for you to get the current tenant within PHP, you will need to let curl follow redirects as /tenant/current is a 302 redirect to the tenant for your API key 因此,要在PHP中获取当前租户,您将需要让curl遵循重定向,因为/tenant/current是302重定向至API密钥的租户

<?php


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.stormpath.com/v1/tenants/current");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = array();
$headers[] = 'Authorization: Basic ' . base64_encode($YOUR_API_KEY_ID:$YOUR_API_KEY_SECRET);
$headers[] = "Accept: application/json";

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$server_output = curl_exec ($ch);

curl_close ($ch);
var_dump($server_output);

With this, it will return your current tenant resource. 这样,它将返回您当前的租户资源。

For reference, Stormpath does have an open PHP SDK that you can use instead so you dont have to mess with cURL at all. 作为参考,Stormpath确实有一个开放的PHP SDK,您可以使用它来代替,因此您完全不必弄乱cURL。

Stormpath PHP SDK Stormpath PHP SDK

The SDK is installable via Composer and is in a stable release state as of 1.12.0 SDK可以通过Composer安装,并且从1.12.0版本开始处于稳定的发布状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM