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

authentication service not return token jwt #571

Closed
SeaDog505 opened this Issue Sep 15, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@SeaDog505
Copy link

SeaDog505 commented Sep 15, 2017

Hi I try authenticate user but I can't. My index file has a login form and these method is POST and action "auth". My authentication service has path "auth". When I give email and password, created is a new user but I want only login without creating new user. All the time I recive that error:

Error authenticating! Object { type: "FeathersError", name: "NotAuthenticated", message: "No auth token", code: 401, className: "not-authenticated", data: Object, errors: Object, stack: "NotAuthenticated: No auth token …" }

I would like to send a form. Next feathers-mongoose checks if an user exists in DB. If an user exists, a script return token jwt.

How to use feathers-authentication.

@daffl

This comment has been minimized.

Copy link
Member

daffl commented Sep 15, 2017

Without additional work you cant' simply POST a form to an authentication endpoint. You can find documentation about how to use authentication in the chat guide (which has a login/signup page in the frontend example), the feathers-chat example repository and the API section.

@daffl daffl closed this Sep 15, 2017

@SeaDog505

This comment has been minimized.

Copy link
Author

SeaDog505 commented Sep 17, 2017

I was create authentication service using: feathers generate authentication My default config file looks like this:

{
"host": "localhost",
"port": 3030,
"public": "../public/",
"paginate": {
"default": 10,
"max": 50
},
"authentication": {
"secret": "My Secret Key",
"strategies": [
"jwt",
"local"
],
"path": "/authentication",
"service": "auth",
"jwt": {
"header": {
"type": "access"
},
"audience": "https://yourdomain.com",
"subject": "anonymous",
"issuer": "feathers",
"algorithm": "HS256",
"expiresIn": "1d"
},
"local": {
"entity": "user",
"usernameField": "email",
"passwordField": "password"
}
},
"mongodb": "mongodb://localhost:27017/myDB"
}

I though I need use the jwt strategy. After changed it I can login but, if the user is not exists is created new but I want can creating a new user only after logged. Unfortunately I can't login through login form. It's work only:

  app.authenticate({
	  strategy: 'local',
	  email: 'myEmail',
	  password: 'myPassword'
	}).then(token => {
	  console.log('User is logged in');
	}).catch(function(error){
	    console.error('Error authenticating!', error);
	  });

Unfortunately not works token jwt. How can I login my user trough login form using POST method. My default service path is /auth I try send data to /auth, /auth/login but it's not working.

@SeaDog505

This comment has been minimized.

Copy link
Author

SeaDog505 commented Sep 17, 2017

How can I verify is token exists? When the token is not exist the route is login page. Thank for reply Daff. Please, explain me when to use jwt strategy and how can I resolve my previously problems.

@SeaDog505

This comment has been minimized.

Copy link
Author

SeaDog505 commented Sep 17, 2017

I did it! I done in this way:

First I check if a token exists:

  app.authenticate({
	  strategy: 'jwt',
	  accessToken: 'your access token'
	}).then(response => {
	  // You are now authenticated
          // I show here an admin's page

	}).catch(function(error){
	    // If a token not exists, then I show login page
	  });

After clicked "log in" button I call this method:

  app.authenticate({
	  strategy: 'local',
	  email: 'myEmail',
	  password: 'myPassword'
	}).then(token => {
	  // I create here a cookie with token value and show admin page
	}).catch(function(error){
	    console.error('Error authenticating!', error);
	  });

I want to ask if this way is good or maybe is better solution? most professional?
I have to ask about path and POST and GET method. How can I send data using login form eg. /auth/login or /auth not using app.authenticate()

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.