From 2c2706a89767de9f3df4cbeda9e8e1dad5e1fa33 Mon Sep 17 00:00:00 2001 From: blsaws Date: Tue, 14 Jun 2016 14:29:41 -0700 Subject: Add API authentication JIRA: COPPER-4 Change-Id: I9f54133037bd74f53640282f63e6294ccacab3aa Signed-off-by: blsaws --- components/congress/test-webapp/www/proxy/index.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'components/congress/test-webapp/www/proxy/index.php') diff --git a/components/congress/test-webapp/www/proxy/index.php b/components/congress/test-webapp/www/proxy/index.php index 5beece5..ed0b6e7 100644 --- a/components/congress/test-webapp/www/proxy/index.php +++ b/components/congress/test-webapp/www/proxy/index.php @@ -23,11 +23,29 @@ if ($method == 'OPTIONS') { exit(); } +$token = file_get_contents("/tmp/os_token"); +if ($result === false) { + $url = "http://KEYSTONE_HOST:5000/v2.0/tokens"; + $curlop = curl_init(); + curl_setopt($curlop, CURLOPT_URL, $url); + curl_setopt($curlop, CURLOPT_CUSTOMREQUEST, "POST"); + curl_setopt($curlop, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curlop, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curlop, CURLINFO_HEADER_OUT, true); + curl_setopt($curlop, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); + $body = '{"auth": {"passwordCredentials": {"username": "OS_USERNAME", "password": "OS_PASSWORD"}}}'; + curl_setopt($curlop, CURLOPT_POSTFIELDS, $body); + $response = curl_exec($curlop); + $response = json_decode($response); + $token = $response->access->token->id; + file_put_contents("/tmp/os_token",$token); +} + $url = "http://CONGRESS_HOST:1789".$_GET['~url']; $curlop = curl_init(); curl_setopt($curlop, CURLOPT_URL, $url); curl_setopt($curlop, CURLOPT_CUSTOMREQUEST, $method); -//curl_setopt($curlop, CURLOPT_HEADER, 0); +curl_setopt($curlop, CURLOPT_HEADER, array('X-Auth-Token: '.$token.'')); //curl_setopt($curlop, CURLINFO_HEADER_OUT, 0); curl_setopt($curlop, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlop, CURLOPT_SSL_VERIFYPEER, false); -- cgit 1.2.3-korg