[OSM-dev] Basic http authentication with OpenStreetMap apis

Erik Johansson emj at kth.se
Fri Jan 21 23:49:46 GMT 2011


On Thu, Jan 20, 2011 at 12:06 PM, Alberto Almagro
<albertoalmagro at gmail.com> wrote:
> Hello,
>
> I'm developing an application that needs to connect to OpenStreetMap's
> API (http://api.openstreetmap.org/ and also
> http://api06.dev.openstreetmap.org/).
>
> I use maven, hibernate, spring and tapestry. When I execute maven's
> test phase, my application establishes connection successfully with
> OSM only adding a header to the http request like the following:
>
> Authorization: Basic bV9qb3NlbmhhbnNAd2fiLmRlOmJsdWVkaWFtb25k
>
> The problems started when I included this use case in the web
> interface, at the beggining it prompted an error telling me that I
> didn't have credentials to connect... so I added the following code:
>
> HttpClient client = new HttpClient();
>                       client.getState().setCredentials(
>                                       AuthScope.ANY,
>                                       new
> UsernamePasswordCredentials(cuentaOsm.getOsmLoginMail(),
> cuentaOsm.getOsmClearPassword()));
>
> And after that it prompts me the following error:
>
> 19-ene-2011 23:26:27
> org.apache.commons.httpclient.auth.AuthChallengeProcessor
> selectAuthScheme
> INFO: basic authentication scheme selected
> 19-ene-2011 23:26:27 org.apache.commons.httpclient.HttpMethodDirector
> processWWWAuthChallenge
> INFO: Failure authenticating with BASIC 'Web
> Password'@api06.dev.openstreetmap.org:80
> 50446 [1481353080 at qtp-730403186-0] ERROR
> org.apache.tapestry5.services.TapestryModule.RequestExceptionHandler -
> Processing of request failed with uncaught exception:
> es.udc.gisapp.model.util.exceptions.ServiceException: HTTP error;
> status code = 401
> org.apache.tapestry5.runtime.ComponentEventException:
> es.udc.gisapp.model.util.exceptions.ServiceException: HTTP error;
> status code = 401 [at
> classpath:es/udc/gisapp/web/pages/applicationservice/MigrarBdOsm.tml,
> line 17]
>
> I don't know what happends, maybe that 'Web Password' realm isn't
> correct... I'm very confused... In the test phase all continues
> working OK.
>
> ¿Any help please?
>

Yeah 'Web Password' is correct, but print the "Authorization: Basic"
headers sent from your library and you will know what went wrong.

bV9qb3NlbmhhbnNAd2fiLmRlOmJsdWVkaWFtb25k
m_josenhans at wg\xe2.de is a strange email


Get a base64 encoding library and do:
HEADER="Authorization: Basic " + base64(username+":"+password)

curl -H "Authorization: Basic HEADER" api.openstreetmap.org/api/0.6/node/create
# this should print "Only method put is supported on this URI"

-- 
/emj



More information about the dev mailing list