cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Implementing HTTP authentication

From: Joshua Kwan <jkwan_at_vmware.com>
Date: Tue, 18 May 2010 13:19:19 -0700

Lyndon Hill wrote on 2010-05-18:
> 1. Set CURLOPT_FAILONERROR to 1
> 2. Try to get the URL
> 3. Check CURLINFO_RESPONSE_CODE for a 401
> 4. If it was 401 then prompt the user for username and password
> 5. Store those details for the next time this URL is required
>
> Is this the right approach ?

This is the approach used by all major browsers today (though for you, the CURLOPT_FAILONERROR is not necessary; you can just check the response code even when CURLE_OK is returned on a transfer. 401 is visible no matter what.)

> Are there some recommendations for storing the username and password ?

Check out 'gnome-keyring'. It functions similarly to the keychain in OS X.

Hope this helps!

-- 
Joshua Kwan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-05-18