简体   繁体   中英

Digest access authentication with javascript

I'm trying to use the cloudapp api with javascript, the problem is that the api is using Digest access authentication for authentication. I visited the app documentation but there is no examples or wrappers for javascript. I tried many things but here is my latest code:

$.ajax({
    headers: { "Accept": "application/json"},
    type: "GET",
    url: "http://my.cl.ly/account",
    crossDomain: true,
    success:function(data, textStatus, request){
        console.log(data);
    }
});

All I'm getting with this code is Cross-origin resource sharing (CORS) problems and a 401 Unauthorized error. here is the response headers:

Cache-Control   no-cache
Connection  keep-alive
Content-Type    text/plain; charset=utf-8
Date    Wed, 17 Sep 2014 20:15:26 GMT
Transfer-Encoding   chunked
WWW-Authenticate    Digest realm="Application", qop="auth", algorithm=MD5, nonce="MTQxMDk4NDkyNjo4MmE4ZWU0ZDY4YWUwYTAyMjRjNzIzYWU2NzE5YTQyMQ==", opaque="9eb56ccb2e8b017ae42bdb4739690863"
X-Request-Id    b6bdbf12-f1d9-4769-a06d-216d5d7ae669
X-Runtime   0.008105
status  401 Unauthorized
x-ua-compatible IE=Edge,chrome=1

So how can I use the WWW-Authenticate to authenticate and retrieve data?

Also I tried adding

xhrFields: {
            withCredentials: true
        }

I got a promt, I filled it and now I'm getting 200 OK status but no response. All I need is to get this working and getting a return. Thanks.

It looks like you're using Digest Access Authentication algorithm. Getting 401 on your first request is a part of algorithm, you have to implement it completely. In WWW-Authenticate header you've got all required fields. I hope this will help you:

http://en.wikipedia.org/wiki/Digest_access_authentication What is digest authentication?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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