0

I have a REST API application, implemented using Express on NodeJs. I wanted to add authentication, and decided to use everyauth, as we need authentication through social network sites in future. I copy & pasted everyauth example for password from https://github.com/bnoguchi/everyauth (Password Authentication section). When I use the connect to implement REST API, a post to

http://localhost:3000/login

enters the everyauth.password.authenticate method. The connect code is as given below.

var connect = require('connect');
connect(
    connect.bodyParser()
  , connect.cookieParser()
  , connect.session({secret: 'whodunnit'})
  , everyauth.middleware()
).listen(3000);

However, when I switch the code to express, as shown below, post to

http://localhost:3000/login

gives 404 - "Cannot POST /login". I am not sure why everyauth is not adding the path "login" to express.

var express = require('express');
var http = require('http');
var everyauth = require('everyauth');

var app = express();

app.configure (function () {
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.session({"secret": "0123456789"}));
    app.use(everyauth.middleware(app));
});

app.listen(3000);

Can someone please help to resolve this.

1 Answers1

0

I figured out what the issue is. It is where app/connect is configured. The app.configure or connect configuration should come after the everyauth.password.authenticate. In my case in connect, I had it after everyauth, and in express I had the configure before everyauth. Hope this helps someone.