I'm trying to get json data from a django view (login required)
into a new android app I'm working on.
I would like to authenticate the user against the django login
and keep the cookie/session for all the django view calls to
get data from the server.
I did some googling but nothing helped me,
even if I guess it should be a quite common task.
Maybe I'm facing the problem from a wrong point of view..
So I'll switch the question to:
how can I do some user authenticated json request/response to a django server?
Any clue?
You have to do as the website expects, and you need to persist the session cookie.
What I did is using XML-RPC to do all the transfers.
Not exactly sure if it's the best way, considering django's xml-rpc support is some kind of a hack.
Here's a very detailed XML-RPC handler for django:
https://code.djangoproject.com/wiki/XML-RPC
then, setup ur client end on android.
When communication is okay. Start writing server end API.
from django.contrib.auth import authenticate
and use this function to do authentication.
Then for sessionId stuff, you need to go to backend db to manually do them: https://docs.djangoproject.com/en/dev/topics/http/sessions/
as u can see, this is why I don't think it's the best way. You can't send httprequest, hence most django build-in functions doesn't work.
Related
I want to make an android app which will login to my web application using rest API. In browsers we have a concept of cookie which servers use to identify/maintain session with the users.
In Android how would we accomplish it ? I heard that there is a concept of token which is sent by server in response(first time when credentials are validated) and Android app have to send it to server every time it tries to access a resource(protected). So, what is the better way of doing it ?
Do we need to validate the token again and again when the client requests for a resource ?
Honestly, I can't think of a better way of doing this. Token based authentication seems to be pretty standard when dealing with RESTful APIs. Is there any reason you can't do that?
If you don't want to change the server code, then this could be simulated by adding a cookie header to every request you send. But this is basically the same thing that you mentioned above, just not as clean.
And the browser is already sending a token to be validated again and again. Every request has a cookie header that gets validated through your web application on every request, so this isn't a big deal at all.
And, you don't need anything Android specific to accomplish this. In whatever http library you're using I'm sure there is a method you can called or something you can override in order to set custom headers. Use that to set either your cookie header or token header on every request that you need to make.
I'm very new to this subject.
I try to build an application server that will interact with clients using Android.
Just before I dive into this field and learn everything, I want to know if there is a proof the design will work.
I build on the fact that the server I want to build can function as well as a client.
For example If a user ask the application server for some data, that my server can POST as a client to another server to get the data to be processed and then handed to the user. Can this work?
again, sorry this is very basic, but I didn't find the specific answer to this and I wanted to make sure I'm not building something "in the air".
All the things you want to do are achievable. It is no problem to let the server make requests to another API to provide the answers back to the client if you want to do sth like this:
Client:
myServer.getWeatherData();
MyServer
public List<WeatherData> getWeatherData() {
//call to local weather station api
}
I have created an AppEngine connected Android application, and I'm trying to modify it to be able to store some user data on the server. I do not know what's the easiest way to do so, because I want it to be as simple as possible. I just want to store some basic data for every user. This data is: Name, Email, and some other Strings. I have created a form in the android side which will allow the user to type all the requested data, but I do not know how to send this information to the GAE server and store it in the datastore. I guess I will have to use a Servlet and some kind of RPC service to call the methods. I'm really lost because it is my first time doing this. I'm not experienced neither in android nor in web apps. I hope you can help me.
Update
Well, maybe I did not explain myself well. The system I've been asked to build consists on a web service that store your personal login credentials for most common sites (facebook, gmail, etc). Using a chrome extension, you ask the server for the credentials on the website you are navigating, and then the server asks to your phone for authorization. It will ask (do you give me permission to send your credentials to "some user"), and you have to ansewer yes or no and then the server will act in consequence. The point is that you have to store your credentials in the server in some way, maybe from the android app (which is what I was trying) or from somewhere else. I will also need authentication.
Pd: I use java for the server side.
Since you already started with AppEngine connected Android application, it makes sense to continue customizing it: App Engine Data Access: Adding Entities and RPC.
Update:
There are of course many ways to exchange data between client and server. The most simple would be a servlet handling GET and POST requests with some query parameters.
Also, most popoular lately is REST:
Android REST client: http://appfulcrum.com/2010/08/20/android-how-to-call-rest-service-using-asynctask/ (try using GSON instead to parse JSON)
Server: use a REST framework. My personal choice is RESTEasy. An example: http://ankiewsky.blogspot.com/2010/08/resteasy-on-googleappengine-corerest.html
Update 2:
The simplest possible way - making/handlin a simple POST request:
Android client - making POST request with parameters: http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient
Server handling POST (or GET) and extracting parameters: http://www.exampledepot.com/egs/javax.servlet/GetReqParam.html
Find and follow thoroughly the Topic Index on this page. Gud luck
I searched similar question here. Couldn't found one, so please excuse if this is duplicate.
I am writing a RESTful webservice using Spring 3.0.5. There will be few REST services which requires user authentication to update few database tables. Our system has USER table, so the authentication should happen against this table. The client is Android devices. The REST request/responses will be XML (not JSON or HTML). Now I have to implement security for the requests. I did search in forums/mailing list, but not able to find a solution for this. Any guide/ideas would be greatly appreciated.
Thanks in advance.
I suspect you'll need to add username and pw to the payload of your rest methods and have the client collect and pass those along.
If you do, you'll need to consider security implications. Encrypting the pw collected from the user and decrypt in your service before passing along or maybe you'd consider simply requiring SSL connection to be sufficient.
Also, you want to make sure youre using POST and not GET to connect to the service as that would expose the username and pw stuff in the url.
I am very new to writing apps so please bear with me!
I am writing an app that needs to communicate securely with a java server (under my control).
Firstly to login to the server, and then send data back and forth. What is the best way of doing this?
My first thoughts was to communicate to a webpage via ssl with the username and password. e.g. login.php with user=xxx and pass=zzz as posted variable. The site returns a random string and saves it in the database.
If the user then stays logged in, this string is saved on the app. This is then sent with every communication. e.g. set_temp.php with string=123456 and temp=20
This seemed easiest to complete, and I have done most of this.
Alternatively, my other thoughts was to go through a sockets approach and commumicate with the Java server directly. Would this be more secure? Is this even possible?
Or are there any other suggestions? How do the big apps like facebook and gmail secure data?
Thanks
Matt
Use SSL protocol. You can create API services on the server and communicate with them. To keep the user logged in use SessionID. Take a look at DefaultHttpClient() class.
I hope this is useful :)
I would use a webservice on your java machine to communicate with. All requests are via HTTPS and you can login the user via the webservice. Also I would add a time limit to the users loggedin session to ensure that he is logged out properly after some time limit.