Welcome Guest, Not a member yet? Register   Sign In
How to use login to CI webService from Android
#1

[eluser]miroslavign[/eluser]
Hi,

I am using the latest download of CI (2.1.0) and have build and
used the web service (REST) from Android application using
Android Asynchronous Http Client from http://loopj.com/android-async-http/
Nothing fancy, just a http helper for android.
Anyways, the stuff works, until I change the login in rest.php
from none ('') to basic or digest.

First of all, i do not understand the difference between basic and digest,
and secondly, how to send user and password to CI ?

So, on Android client I've tried:
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("username", "admin");
params.put("password", "1234");
client.get("http://10.0.2.2/Menjacnica/index.php/api/menjacnice_api/menjacnice",
params, new AsyncHttpResponseHandler()...

and it does not work.

Again, if on the CI side I return to no login (''), the Android client is getting
the correct response from my CI controller.

Any ideas?
#2

[eluser]gRoberts[/eluser]
Is your REST api expecting GET or POST to perform the login?

Looking at your URL, it's post, but looking at your AsyncHttpClient code, your performing a GET.
#3

[eluser]miroslavign[/eluser]
It is working with get:

...
function menjacnice_get()
{
...

And it is working as expected when the REST login is none
#4

[eluser]gRoberts[/eluser]
I'm not 100% sure on how the REST api works, however, it's likely that yours is configured to accept login's that are in "plaintext", which I assume Login type '' uses.

Digest (http://en.wikipedia.org/wiki/Digest_acce...entication) and Basic (http://en.wikipedia.org/wiki/Basic_acces...entication) both encrypt/hash the username/password when passing it to the server to login, so it's likely that it's failing because your Android app is not encryping/hashing the username/password correctly.
#5

[eluser]miroslavign[/eluser]
I don't if that might be the problem,
but it is worth trying to investigate.
#6

[eluser]miroslavign[/eluser]
It seem you were right,

in Android Asynchronous Http Client, there is a patch that
adds a method: public void setBasicAuthCredentials(String user, String pass)
that adds a Base64 encoding !
Will try to patch and build a newer lib right now.

Thank you gRoberts
#7

[eluser]miroslavign[/eluser]
Yes, it works now!

Should mark this as resolved.




Theme © iAndrew 2016 - Forum software by © MyBB