Re: 401 error



OK, well, it looks like the problem is that libsoup isn't sending the
username+password on the initial request (which is correct, since it
doesn't know that the server wants to use Basic auth), and the server is
returning 500 rather than 401. Which it really shouldn't do, but...

Try adding this right after you first create the session:

  let msg = Soup.Message.new("GET", this.owncloudUrl);
  let auth_mgr = httpSession.get_feature(Soup.TYPE_AUTH_MANAGER);
  let auth = Soup.Auth.new(Soup.TYPE_AUTH_BASIC, msg, "Basic realm=dummy");
  auth_mgr.use_auth(auth);

-- Dan

On 07/17/2015 11:19 AM, Sam Bull wrote:
Here is the logs after adding the logger, hopefully that's the right data.

http://pastebin.com/tTW2Qx28

On Thu, 16 Jul 2015, at 06:38 PM, Dan Winship wrote:
Can you try adding a SoupLogger (see my previous message) to get it to
log the request and response bodies? Or just tcpdump the traffic if
you're using plain http...

On 07/16/2015 11:46 AM, Sam Bull wrote:
On Thu, 2015-07-16 at 10:00 -0400, Dan Winship wrote:
It's impossible to say for sure what's wrong without seeing more
information. Eg, the rest of the code, or a copy of the HTTP request and
response.

The code is basically:

        let msg = Soup.Message.new("GET", "http://user:password myowncloudurl 
com/index.php/apps/notes/api/v0.2/notes");
        httpSession.queue_message(msg, Lang.bind(this, this.owncloudSync));

You can view the actual code at:
    https://extensions.gnome.org/review/4999
The code in question is in notesData.js around lines 60-70.

You can also install the extension if you want to have a play around
with the code (I can send you test login details if needed).

Having just tried to run this again, I noticed that I'm on a newer
version of ownCloud, and now it returns a 500 error instead of the 401
error it used to. This might be more helpful as I am able to get the
error logs from ownCloud. I'm not sure exactly what to make of this, but
it is clear that the login is failing. Again, the 500 error appears when
accessing the URL in the browser or with Soup.Message.new() but works
perfectly with curl (and worked with libsoup in shell versions before
3.14).

Error logs:
        {"reqId":"cE665WovcyEnnliIc7bf","remoteAddr":"109.170.159.240","app":"PHP","message":"Undefined 
index: PHP_AUTH_USER at \/var\/www\/owncloud\/
        
lib\/private\/appframework\/middleware\/security\/corsmiddleware.php#81","level":3,"time":"2015-07-16T15:26:46+00:00","method":"GET","url":"\/
        index.php\/apps\/notes\/api\/v0.2\/notes"}
        {"reqId":"cE665WovcyEnnliIc7bf","remoteAddr":"109.170.159.240","app":"PHP","message":"Undefined 
index: PHP_AUTH_PW at 
\/var\/www\/owncloud\/lib\/private\/appframework\/middleware\/security\/corsmiddleware.php#82","level":3,"time":"2015-07-16T15:26:46+00:00","method":"GET","url":"\/index.php\/apps\/notes\/api\/v0.2\/notes"}
        {"reqId":"cE665WovcyEnnliIc7bf","remoteAddr":"109.170.159.240","app":"core","message":"Login 
failed: '' (Remote IP: 
'109.170.159.240)","level":2,"time":"2015-07-16T15:26:46+00:00","method":"GET","url":"\/index.php\/apps\/notes\/api\/v0.2\/notes"}
        
{"reqId":"cE665WovcyEnnliIc7bf","remoteAddr":"109.170.159.240","app":"index","message":"Exception: 
{\"Exception\":\"OC\\\\AppFramework\\\\Middleware\\\\Security\\\\SecurityException\",\"Message\":\"CORS 
requires basic auth\",\"Code\":0,\"Trace\":\"#0 
\\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/appframework\\\/middleware\\\/middlewaredispatcher.php(92):
 
OC\\\\AppFramework\\\\Middleware\\\\Security\\\\CORSMiddleware->beforeController(Object(OCA\\\\Notes\\\\Controller\\\\NotesApiController),
 'index')\\n#1 
\\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/appframework\\\/http\\\/dispatcher.php(88): 
OC\\\\AppFramework\\\\Middleware\\\\MiddlewareDispatcher->beforeController(Object(OCA\\\\Notes\\\\Controller\\\\NotesApiController),
 'index')\\n#2 \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/appframework\\\/app.php(108): 
OC\\\\AppFramework\\\\Http\\\\Dispatcher->dispatch(Object(OCA\\\\Notes\\\\Controller\\\\NotesApiController),
 'index')\\n#3 \\\/var\\\/www\\\/owncloud
 \\
 \/lib\\\/
private\\\/appframework\\\/routing\\\/routeactionhandler.php(45): 
OC\\\\AppFramework\\\\App::main('NotesApiControl...', 'index', 
Object(OC\\\\AppFramework\\\\DependencyInjection\\\\DIContainer), Array)\\n#4 [internal function]: 
OC\\\\AppFramework\\\\routing\\\\RouteActionHandler->__invoke(Array)\\n#5 
\\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/route\\\/router.php(274): 
call_user_func(Object(OC\\\\AppFramework\\\\routing\\\\RouteActionHandler), Array)\\n#6 
\\\/var\\\/www\\\/owncloud\\\/lib\\\/base.php(867): 
OC\\\\Route\\\\Router->match('\\\/apps\\\/notes\\\/api...')\\n#7 
\\\/var\\\/www\\\/owncloud\\\/index.php(40): OC::handleRequest()\\n#8 
{main}\",\"File\":\"\\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/appframework\\\/middleware\\\/security\\\/corsmiddleware.php\",\"Line\":86}","level":4,"time":"2015-07-16T15:26:46+00:00","method":"GET","url":"\/index.php\/apps\/notes\/api\/v0.2\/notes"}
        {"reqId":"c39IygEQ2lhfN2BG\/+64","remoteAddr":"","app":"PHP","message":"Undefined index: 
REQUEST_URI at 
\/var\/www\/owncloud\/apps\/contacts\/appinfo\/app.php#35","level":3,"time":"2015-07-16T15:30:01+00:00","method":"--","url":"--"}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]