Jens Bergvall
Jens Bergvall

Reputation: 1627

How to deal with domain authentication in android app?

We have a server on which we have a web service. And to access the functions on the service, we need to bypass this domain-authentication. We would also like for the session to last until the user chooses to close the session.

Edit: Not bypass, we need to authenticate ofc..

Authentication message

It basically sais: Authentication needed. Please provide your username and password for http://foo.bar

This was easily solved using Xcode and objc, but now we're developing for Android, and we have yet to find a good way to deal with this domain authentication.

We are not using any webviews, so to make this pop up is out of the question.

So far we've tried using ksoap2, changing HttpTransportSE to HttpsTransportSE but without success.

Has anyone dealth with this, if so, thou shalt shareth with me thy ways! J/K No, but seriously, links to material and pointers would be highly appreciated.

Also, feel free to ask for more details, as we have somewhat full control over the web-service.

Upvotes: 0

Views: 836

Answers (1)

Simon Gauld
Simon Gauld

Reputation: 26

It sounds you have a webservice with some form of http authentication required - basic or digest perhaps.

If you're going to use HttpClient on android, something like the following should handle the challenge:

.
.

String username = ....
String password = ....
DefaultHttpClient httpClient = new DefaultHttpClient();
if (username != null) {
  httpClient.getCredentialsProvider().setCredentials(
       new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
       new UsernamePasswordCredentials(username, password));
}

.
.


httpClient.execute(your_http_request); 

.
.

Upvotes: 1

Related Questions