Digest authentication with SOAP

325 views
Skip to first unread message

Marcel Krcah

unread,
Dec 4, 2014, 10:12:24 AM12/4/14
to sca...@googlegroups.com
Hi there,

I'm struggling to setup a digest authentication on SOAP service. It seems that only Basic Auth is supported out-of-the-box.

I'm providing the Digest realm in the DispatchClientAsync as follows:

import com.ning.http.client.Realm.{RealmBuilder, AuthScheme}

trait DispatchHttpClientsAsync extends HttpClientsAsync {
lazy val httpClient = new DispatchHttpClient {}

trait DispatchHttpClient extends HttpClient {
import dispatch._, Defaults._

val http = new Http()
def request(in: String, address: java.net.URI, headers: Map[String, String]): concurrent.Future[String] = {

val realm = new RealmBuilder()
.setScheme(AuthScheme.DIGEST)
.setRealmName("Digest") // as returned from the server
.setPrincipal("<username>")
.setPassword("<password>")
.setNonce("<Here I manually copy the nonce returned from server. If it works, I'll automatize this>")
.setAlgorithm("MD5-sess") // as returned from the server
.build()

val req = url(address.toString).setBodyEncoding("UTF-8").setRealm(realm) <:< headers << in
http(req > as.String)
}
}
}


However, I'm still getting 401 Not Authorized.

I tried SoapUI, the credentials are ok. Before I run this code, I manually replace the nonce with a fresh one coming from the server.

Is there something I'm missing? 

Thanks.

Marcel Krcah

unread,
Dec 4, 2014, 11:11:35 AM12/4/14
to sca...@googlegroups.com
Actually, the ning library performs the whole digest dance for you.
It performs one requests to get digest details and then automatically fills in the digest authorization header in the next request (incl. nonce, realm, algo, etc.). 

Thus, the code can be simplified as follows: 

val realm = new RealmBuilder()
.setScheme(AuthScheme.DIGEST)
  .setPrincipal("<username>)
.setPassword("<password>")
  .build()

However, the 401 is still there :)
Reply all
Reply to author
Forward
0 new messages