Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 03-07-2013, 04:08 AM   #1
maku
Junior Member
maku began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Mar 2013
Device: Android
http ajax request authentication

HI,

I would like to use calibre server ajax functionality.

For authentication purposes: Can anybody of you give me a hint how to do this with javascript (I want to develop a calibre mobile app based on phonegap).

How do I send the correct authentication information to the server?

TIA

Martin
maku is offline   Reply With Quote
Old 03-07-2013, 04:15 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
The server supports http digest authentication. Ajax based authentication is insecure without https and you cant use https on a private server (the certificate wont validate).
kovidgoyal is offline   Reply With Quote
Advert
Old 03-07-2013, 06:41 AM   #3
maku
Junior Member
maku began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Mar 2013
Device: Android
Quote:
Originally Posted by kovidgoyal View Post
The server supports http digest authentication. Ajax based authentication is insecure without https and you cant use https on a private server (the certificate wont validate).
Thanks for answering:
would it be possible to provide a dedicated login call which returns a token (or maybe it is enought to get the session cookie)- where username and password are sent encrypted ?

TIA
Martin
maku is offline   Reply With Quote
Old 03-07-2013, 07:05 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Implementing such a thing securely is not a job lightly undertaken. It isn't one that I have the time for, but patches are welcome.

In any case, what's preventing you from using digest auth for your ajax calls? That's what the current calibre content server frontend does.
kovidgoyal is offline   Reply With Quote
Old 03-07-2013, 07:28 AM   #5
maku
Junior Member
maku began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Mar 2013
Device: Android
I tried to pass username and password to jquery's ajax function -> which works successfully.
It seems that query handles the autentication process behind the seems....
But I'm not really sure if this approach is secure...

Do you think it is a reasonable way to provide username/passwort on every jquery ajax call?
maku is offline   Reply With Quote
Advert
Old 03-07-2013, 09:01 AM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You should need to do anything, the browser will automatically provide suername password when using ajax once the user has entered it for the initial page load.
kovidgoyal is offline   Reply With Quote
Old 03-08-2013, 09:41 AM   #7
maku
Junior Member
maku began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Mar 2013
Device: Android
Unfortunately under Android (with Phonegap/cordova) it seems not possible to pass the username/password combination to the server via jquery's ajax call - get "Unauthorized" error...
maku is offline   Reply With Quote
Old 03-08-2013, 10:50 AM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You dont pass the username/password via ajax. What you do is direct the browser to the server home page. The browser will then ask the user for the username/password. Once the user provides it, the browser automatically uses it for future ajax calls to the same domain.
kovidgoyal is offline   Reply With Quote
Old 03-08-2013, 11:40 AM   #9
maku
Junior Member
maku began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Mar 2013
Device: Android
Quote:
Originally Posted by kovidgoyal View Post
You dont pass the username/password via ajax. What you do is direct the browser to the server home page. The browser will then ask the user for the username/password. Once the user provides it, the browser automatically uses it for future ajax calls to the same domain.
Yes, but this is not the use case I want to achieve.

I want a mobile cross plattform calibre client written with cordova/phonegap. This means that the app is delivered as native app. Under the hood it works like a local web app -> html / js / css etc. is therefore within the native mobile app. This app should communicate with calibre server (only via ajax calls to get data from the server) And thats the problem...
When I try it e.g. with google chrome and certain development flags (--disable-web-security -–allow-file-access-from-files) auth. works fine... (jquery ajax call handles apparently the authentification procedure) -> but with the android app it doesn't work...
maku is offline   Reply With Quote
Old 03-08-2013, 11:47 AM   #10
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Then you're out of luck. I for one have have no interest in that use case. If you want to write a html/js interface to calibre, write one as part of the content server, there's absolutely no need to have it delivered as a "native" app.
kovidgoyal is offline   Reply With Quote
Old 09-22-2014, 04:56 PM   #11
plugin_dev
Junior Member
plugin_dev began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Sep 2014
Location: Edinburgh
Device: Kindle
jQuery absolutely can perform HTTP basic authentication, for AJAX calls. See here for a demonstration:

https://www.mobileread.com/forums/sho...d.php?t=207644
plugin_dev is offline   Reply With Quote
Old 09-23-2014, 02:46 AM   #12
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
FWIW: calibre companion is a native android app and it uses digest authentication and ajax. All we needed to do was set up the correct security environment in the http connection.
Code:
		// Set up authentication. Try digest before basic
		List<String> authpref = new ArrayList<String>();
		authpref.add(AuthPolicy.DIGEST);
		authpref.add(AuthPolicy.BASIC);
		httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
Of course, if you do not have access to the underlying http connection then this scheme will not work.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP Error 407: Proxy Authentication Required pieterwiese Devices 11 06-11-2012 02:23 AM
HTTP Request - Mimic Different Browsers? EnergyLens Recipes 4 06-13-2011 02:01 PM
http://www.morphzone.org request please trott3r Recipes 11 10-15-2010 02:20 PM
Calibre Content Server HTTP Authentication - Basic or Digest? Jim Chapman Calibre 6 10-04-2010 12:09 PM
HTTP authentication for feeds with calibre DAiki Calibre 2 10-12-2008 08:49 AM


All times are GMT -4. The time now is 04:27 AM.


MobileRead.com is a privately owned, operated and funded community.