Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login not working on PhoneGap's http://192.168.0.3:3000/ #226

Open
nijakobius opened this issue Mar 10, 2018 · 5 comments
Open

Login not working on PhoneGap's http://192.168.0.3:3000/ #226

nijakobius opened this issue Mar 10, 2018 · 5 comments

Comments

@nijakobius
Copy link

Trying to implement a login system with this plugin (in PhoneGap):

Code

remoteDB = new PouchDB('https://MYACCOUNT.cloudant.com/DATABASE');

remoteDB.logIn('USER', 'PASSWORD').then(function(response) {
console.log(response);
});

remoteDB.getSession(function (error, response) {
console.log(response);
});

Current Behaviour

  1. It works if I open the index.html from the macOS Finder, such that the address bar reads file:///Users/USER/Documents/pouchdblogin/www/index.html.

  2. However, if I run it via PhoneGap (http://192.168.0.3:3000/), the login doesn't seem to work:

In both cases, the logIn response is

{roles: Array(0), ok: true, name: "fb10213293253078466"}

But the getSession responses are different:

1. For file:///..........:

info.authenticated: "cookie"
userCtx.name: "USER"

-> Expected behaviour

2. but for http://192.168.0.3:3000/ it is:

info.authenticated: "local"
userCtx.name: null

-> Login didn't work properly

Am I doing something wrong?

Environment

  • Version of PouchDB Authentication: 1.1.2
  • Version of PouchDB: 6.4.3
  • Server: Cloudant
@ptitjes
Copy link
Collaborator

ptitjes commented Mar 11, 2018

Hi @nielsjakob, thanks very much for your detailed report.

I have difficulties figuring out what your problem is, also maybe because I don't Cloudant. I will think about it and come back to you if I understand what is going on.

In the meantime, would you mind:

  • giving us the full JSON object that is returned by getSession()
  • telling us what browsers are used for both your cases 1. and 2.

Thank you in advance.

@nijakobius
Copy link
Author

Thanks for your reply, @ptitjes

  • I have tested this in Safari 11.0.3 and Chrome 64.0.3282.186 (Official Build) (64-bit). Same result.

screen shot 2018-03-14 at 12 06 11

When I encounter the problem described in my original post, I get the normal browser authentication popup. When I type in my login info, the session gets stored and everything. So while it doesn't work exactly how it should, with this workaround, it's fine for testing on my computer.

Also, I found out that after compiling my PhoneGap app and running it on iOS and Android, it works as expected. It's really just when I run it on PhoneGap's local server.

@ptitjes
Copy link
Collaborator

ptitjes commented Mar 14, 2018

@nielsjakob If you have the browser authentication popup, this means you have Basic Authentication activated on you database. You might want to disable it and just use Cookie Authentication (+ SSL on production server). I think that would solve your problem.

@nijakobius
Copy link
Author

Is this something that's done in new PouchDB()? Some header I have to set?

remoteDB = new PouchDB('https://MYACCOUNT.cloudant.com/DATABASE', {
    ajax: { headers: { authorization: ??? } }
});

@ptitjes
Copy link
Collaborator

ptitjes commented Apr 6, 2018

@nielsjakob Sorry for the late reply.

To disable Basic Authentication on your remote database, you must modify the configuration of your remote CouchDB database host.

If you cannot disable it (which maybe you can't on Cloudant), then in order to suppress the authentication popup on the client side, try to add some skip_setup and auth options to the PouchDB constructor call:

remoteDB = new PouchDB('https://MYACCOUNT.cloudant.com/DATABASE', {

   // to disable contacting the database before logging (and show the popup)
   skip_setup: true,

   // to configure the Basic Authentication credentials
   auth: {
      username: 'username',
      password: 'password'
   }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants