is it possible to call identity restful api with javascript

Asked by jiangkai zhang

I want to call identity restful api with ajax in my html page,my code as below:
<html><head><title>test identity restful api</title>
<script type="text/javascript" src="json.js"/>
<script type="text/javascript">
var xmlHttp;
function initXmlHttp()
{
if(window.XMLHttpRequest){xmlHttp=new XMLHttpRequest();}
else if(window.ActiveXObject){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
}

function statechange()
{
if(xmlHttp.readystate==4 && xmlHttp.status==200){document.getElementById("id1").innerHTML=xmlHttp.responseText;}
}

function sendRequest()
{
var data={
    "auth":{
        "passwordCredentials":{
            "username":"admin",
            "password":"openstack"
        },
        "tenantName":"Admin"
    }
};
initXmlHttp();
xmlHttp.open("POST","http://192.168.2.62:5000/v2/tokens",true);
xmlHttp.onreadystatechange=statechange;
xmlHttp.setRequestHeader("Content-Type","application/json");
xmlHttp.setRequestHeader("Accept","application/json");
xmlHttp.send(JSON.stringify(data));
}

</script>

</head>
<body>
<div id="id1"></div><br/>
<input type="button" value="test api" onclick="javascript:sendRequest();"/>
</body>
</html>

I still get 404 error information in firefox firebug console,I get totally confused,any help will be appreciated!

Question information

Language:
English Edit question
Status:
Answered
For:
OpenStack Identity (keystone) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
xyj (xyj-asmy) said :
#1

try "http://192.168.2.62:5000/v2.0/tokens" instead of "http://192.168.2.62:5000/v2/tokens"

at least, v2 will get 404 via curl.

Revision history for this message
jiangkai zhang (jekie8) said :
#2

i have also tried "http://192.168.2.62:5000/v2.0/tokens",the result is disappointing too....

Revision history for this message
Joseph Heck (heckj) said :
#3

Im afraid I don't know javascript well enough to help tell you what's not happening correctly. The data structure you're sending looks generally correct to request a token.

The correct API URI is /v2.0/tokens to request a token with credentials.

I recommend that you watch the logs of keystone while you're making this request, and make sure that "debug" is in the pipeline for the public API - that will dump out everything that keystone is seeing form the request, and may make debugging easier.

relevant lines in ``keystone.conf``::

    [pipeline:public_api]
    pipeline = token_auth admin_token_auth xml_body json_body debug ec2_extension public_service

Revision history for this message
yong sheng gong (gongysh) said :
#4

Correct url should be: http://localhost:5000/v2.0/tokens.

But the main problem should be about cross-domain.

please have a look at http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/

Can you help with this problem?

Provide an answer of your own, or ask jiangkai zhang for more information if necessary.

To post a message you must log in.