Authentication to ODK via Python

Hello everybody,

I need your help about a subject which bored me a lot

I am making an application in Python which parse a message in xml qnd send
it to the odk aggregate server

I managed to upload my xml file in the server using appspot and
MultipartPostHandler because I have a real form and i can send a real HTTP
request but I don't understand how can i do for the authentication,

I tried a lot of thing , from everywhere and i Don t know if all those
think didn t work because of the way of authentificate with odk or because
of my code

I would need a clue, just which kind of authentificqtion can we do, basic
httpauth, etc ...

I will tqke cqre of the implementqtion but I have qbsolutly no idea where
to search

thank you in advance
Regards
Sorry for the english, i am not native speaker

On ODK Aggregate, create an ODK Aggregate username (e.g., 'submitter'),
grant it Data Collector rights, and Change Password to give it a password
(if you do not set a password, the user will have an invalid, unknowable,
password, and you will not be able to use it for logins).

The login mechanism used for these ODK Aggregate usernames is an old old
standard, called Digest Auth ( http://www.ietf.org/rfc/rfc2617.txt ).

Every http communications framework should have tools to use this mechanism
with very little effort. Most frameworks have a notion of an HttpContext
that holds the session cookies and state for a session. This context is
then used in all communications to the server. If you don't specify one, a
default empty context is used for each request.

The general steps, for authenticated communications is:

(1) obtain a HttpContext
(2) access the credentials manager in the context, and insert the (
hostname, username, password, authentication mechanism: DigestAuth ) tuple
into the credentials manager.
(3) make Http PUT and GET requests using this HttpContext

During those requests, the credentials manager in the context will use the
saved information about the hostname, username, password and authentication
mechanism to handle all authentication handshakes with the server, without
any need for any other code in your app.

Mitch

··· On Wed, May 22, 2013 at 9:18 AM, Stéphane CapmartiTSF wrote:

Hello everybody,

I need your help about a subject which bored me a lot

I am making an application in Python which parse a message in xml qnd send
it to the odk aggregate server

I managed to upload my xml file in the server using appspot and
MultipartPostHandler because I have a real form and i can send a real HTTP
request but I don't understand how can i do for the authentication,

I tried a lot of thing , from everywhere and i Don t know if all those
think didn t work because of the way of authentificate with odk or because
of my code

I would need a clue, just which kind of authentificqtion can we do, basic
httpauth, etc ...

I will tqke cqre of the implementqtion but I have qbsolutly no idea where
to search

thank you in advance
Regards
Sorry for the english, i am not native speaker

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Hello,

Perfect thank you very much, that is exactly the kind of message I was
waiting for.

I will try this and keep you in touch via this discussion

Thank you very much and Have a nice day

Regards

Stéphane

Hello,
It is crazy I really don't understand
I tried like you said, I find some good tutorial end it does not seem
complicated
it does not work

So I Tried another way, using google auth tokens, I was pretty sure it
would work but same thing
It is a dummy program I just try to access the submission page with out
uploading my form

If someone could just have a look please I would appreciate

thank you in advance
regards

r2.py (2.17 KB)

testauth.py (587 Bytes)

Sorry, I can't provide this level of assistance.

··· On Thu, May 23, 2013 at 8:39 AM, Stéphane CapmartiTSF wrote:

Hello,
It is crazy I really don't understand
I tried like you said, I find some good tutorial end it does not seem
complicated
it does not work

So I Tried another way, using google auth tokens, I was pretty sure it
would work but same thing
It is a dummy program I just try to access the submission page with out
uploading my form

If someone could just have a look please I would appreciate

thank you in advance
regards

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

very late reply, I'm exploring the matter myself.
assuming your ODK Aggregate server is running at your-server.appspot.com, ...

import requests
from requests.auth import HTTPDigestAuth
auth = HTTPDigestAuth('your_user', '*********')
form_id = 'your_form_id'
base_url = 'https://your-server.appspot.com/view/submissionList'
result = requests.get('%s?formId=%s' % (base_url, form_id), auth=auth)

the above works for me in the sense that I get a code 200 reply from the server and it contains indeed a list of forms.

what we do now is to loop through the id elements in the idList in the above reply.

you have your form xml definition, haven't you? well, it contains elements looking like:
<input ref="/plant_form/acc_no_scan"> ... from here you need the leading part, the one similar for all, in my case it's plant_form. I will call it group_name.

for each of them:

base_url = 'https://your-server.appspot.com/view/downloadSubmission'
form_filter = '@version=null and @uiVersion=null'
group_name = 'plant_form'
key = "<the value from the id element>"
result = requests.get('%s?formId=%s[%s]/%s[@key=%s]' % base_url, form_id, 
                                            form_filter, group_name, key, 
                      auth=auth)

and this serves me.

oh, but you only wanted authentication. well, that's part of this far too verbose answer.

1 Like