stormpath/express-stormpath

No default /login route

suederade opened this issue · 7 comments

The docs say:

When you add Stormpath to your application using app.use(stormpath.init(app)), our module will automatically add the following routes to your application:

And inside the Login section it then says:

If you want to make a login attempt from a front-end application (Angular, React), simply post a JSON body to the /login endpoint, with the following format:

I have the very simple application:

let express = require('express');
let stormpath = require('express-stormpath');

let app = express();

app.use(stormpath.init(app, {
	web: {
	    produces: ['application/json']
	}
}));

app.listen(3000);

// Stormpath will let you know when it's ready to start authenticating users.
app.on('stormpath.ready', function () {
  console.log('Stormpath Ready!');
});

And when I make a post to the server I get this error:

Cannot POST /login

As far as I can see from the docs, there doesn't seem to be anything in my code that is incorrect.

Hi @stevenmwade , thanks for reaching out! Can you show us how you're making a POST to /login? If the request prefers text/html, you'll get a 404 from this endpoint when it's configured to only produce json.

@robertjd I am making the POST with Postman and setting the content-type to appplication/json, but I can try with plain text.

Which doesn't make any change.

I have a user set up from some other stormpath tests and I am sending it this:

{
  "username": "tk421@stormpath.com",
  "password": "Changeme1"
}

Can you look at the Accept header that postman is sending on the request? The Accept header is the header that a client uses to tell the server which content type it wants the response to be in. The Content-Type header is declaring the format of the data that is being sent to the server.

Connection →keep-alive
Content-Length →19
Content-Type →text/html; charset=utf-8
Date →Wed, 14 Dec 2016 19:53:43 GMT
X-Content-Type-Options →nosniff
X-Powered-By →Express

It looks like you need to add Accept: application/json to the request.

@robertjd Nailed it. I'm surprised Postman isn't setting those itself. Thank you sir.

No prob, happy to help! I actually think we should handle this better on our side, we should infer the lack of an Accept header to mean you want the only configured response type.