Question

I'm making a plugin for etherpad that checks if the user is authenticated. If not it displays the read only. I got this far:

var eejs = require('ep_etherpad-lite/node/eejs');
var readOnlyManager = require("ep_etherpad-lite/node/db/ReadOnlyManager");

exports.route = function(hook_name, args, cb){
    args.app.get('/p/:pad', function(req, res){
        if(req.params.pad.indexOf('r.') === 0){
            res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {req: req}));
        } else {
            if(req.session.user){
                res.send(eejs.require("ep_etherpad-lite/templates/pad.html", {req: req}));
            } else {
                readOnlyManager.getReadOnlyId(req.params.pad, function(err, readonlyID){
                    res.redirect('/p/'+readonlyID);
                });
            }
        }
    });
}

exports.logout = function(hook_name, args, cb){
    args.app.get('/logout', function(req, res){
      req.session.destroy(function(){
        res.redirect('/');
      });
    });
}

But I can't use post routes to make my own user login. How can I have something like the general authentication on request, let's say when I visit /login?

Was it helpful?

Solution

I wrote a lot of the auth mechanism in Etherpad but it was years ago and I don't know how much it's changed since.

The API endpoints you need and documentation for how auth works is available in the Etherpad documentation and specifically auth is discussed in the authentication documentation.

It's hard to tell from your question but it looks like you want to have some sort of login page at /login? If so, review how Etherpad already implements basic auth and adapt it by creating a new express endpoint at /login

There are various plugins (including ones I have developed) that can be used to create new express endpoints, an example is available in the ep_email_notifications Etherpad plugin

Did I get the right end of the stick from your question?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top