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

using feathers-rest/client with feathers-authentication/client #94

Closed
kurdin opened this Issue Mar 4, 2016 · 7 comments

Comments

Projects
None yet
4 participants
@kurdin
Copy link

kurdin commented Mar 4, 2016

I am trying to connect another NodeJs Server with working FeathersJs services vi feathers-rest/client, APIs work fine with PostMan with auth and everything.

Simple code for connecting to FeathersJs services without feathers-authentication/client works fine:

const url = 'myAPI.domain.com'
const restClient = require('feathers-rest/client');
const superagent = require('superagent');

let api = restClient(url).superagent(superagent);
api.service('users/count').get().then(count => {
    console.log('users:', count);
}).catch(err => {
     console.log(err)
});

console# users: { count: 10 }

I want to add feathers-authentication/client to login first before I can use services, that does not working at all for some reasons:

const url = 'myAPI.domain.com'
const restClient = require('feathers-rest/client');
const feathers = require('feathers/client');
const authentication = require('feathers-authentication/client');
const hooks = require('feathers-hooks');
const superagent = require('superagent');

let api = restClient(url).superagent(superagent);
let app = feathers()
        .configure(api)
        .configure(hooks())
        .configure(authentication());

app.authenticate({
    type: 'local',
    email: 'test@test.com',
    password: 'test'
}).then(result => {
    console.log('Authenticated!', result);
}).catch(error => {
    console.error('Error authenticating!', error);
});

app.service('users/count').get().then(count => {
    console.log('users:', count);
}).catch(err => {
    console.log(err)
});

I got 2 kind of errors: 
{ [Error: Not Found]
        ...
        statusCode: 404,
        statusMessage: 'Not Found',
        ...
        text: 'Cannot GET /storage/user\n',
...
}
or 
{ [Error: Not Found]
        ...
        statusCode: 404,
        statusMessage: 'Not Found',
        ...
        text: 'Cannot GET /storage/token\n',
...
}

app.authenticate does not return anything. The errors from app.service call for some reason its trying to do requests /storage/user and /storage/token endpoints instead of /users/ and auth/token.

Any ideas?

Versions I use:
feathers: 2.0.0
feathers-rest: 1.2.2
feathers-authentication: 0.4.1

@jack-guy

This comment has been minimized.

Copy link

jack-guy commented Mar 5, 2016

It's not all that well documented at the moment, but you'll need to use feathers-localstorage to get feathers-authentication working. npm install feathers-localstorage and then

    let app = feathers()
      .configure(rest(url).superagent(superagent))
      .configure(hooks())
      .use('storage', localstorage())
      .configure(authentication());

The error you're getting is feathers-client not having the localstorage config which fills those missing URLs. :)

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Mar 5, 2016

@harangue is absolutely right. I'll update some of the docs ove me the next couple days. Have a bunch of updates coming to auth soon. 😀

@kurdin

This comment has been minimized.

Copy link
Author

kurdin commented Mar 5, 2016

Yes, I figured out about localstorage module and correct code is this:

  const localstorage = require('feathers-localstorage');
  const storage = require('localstorage-memory');
...
    let app = feathers()
      .configure(rest(url).superagent(superagent))
      .configure(hooks())
      .use('storage', localstorage({storage: storage}))
      .configure(authentication());

but this is not the only problem. Still that code does not work because this line does not set Authorization headers correctly.

https://github.com/feathersjs/feathers-authentication/blob/master/src/client/hooks.js#L22
[options.header || 'Authorization']: hook.params.token
should be
[options.header || 'Authorization']: hook.params.token.value

hook.params.token is the object and token string exists in key value

Anyhow, seems to me that feathers-client and feathers-authentication client with so many modules just overkill at least for Server to API Server communication. Maybe it is better to stick with simple/common rest client solution based on standard http module.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Mar 6, 2016

@kurdin I had run into that as well. I thought I had fixed the token reference but I guess not. Sorry about that. I've created an issue for it (#95). Thanks for reporting that!

On the other issues, yes you need to have localstorage configured. I've added explicit checks for that in the code now, it's on master but not published. Also, you need to initialize your user service before you can authenticate because it tries to look up your user via the user service in order to compare passwords. I think that was your original issue.

The problem with standard HTTP auth or basic auth is that you can't do that over sockets and we wanted to have an abstracted interface over REST and sockets for OAuth, and local auth.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Mar 6, 2016

I'm going to close this one, as we can track the remaining issue (#95) separately.

@ekryski ekryski closed this Mar 6, 2016

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Mar 6, 2016

I guess my one authentication client test did not cover this. The client definitely needs some thorough tests.

@ekryski

This comment has been minimized.

Copy link
Member

ekryski commented Mar 23, 2016

The syntax used in this issue is now deprecated. Please refer to http://docs.feathersjs.com/authentication/readme.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.