flatiron-persona
Version:
Flatiron plugin for user authentication with Mozilla Persona
70 lines (63 loc) • 2.37 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var $, debug, _;
_ = require("underscore");
debug = require("debug");
$ = debug("persona");
module.exports = {
name: "flatiron-persona",
attach: function(options) {
var defaults, routes;
$ = debug("persona:attach");
defaults = {
path: "/auth",
audience: void 0
};
_.defaults(options, defaults);
$("Options: %j", options);
if (!options.audience) {
throw new Error("flatiron-persona: Audience not set.\n\nYou must provide an audience in options, eg.\n\n app.use persona, audience: \"http://myapp.example.com/\"\n\nLearn more about audience here: https://developer.mozilla.org/en-US/docs/Persona/Quick_Setup#Step_4.3A_Verify_the_user.E2.80.99s_credentials\n");
}
if (this.router == null) {
throw new Error("flatiron-persona: There is no router in your app.\n\nThis plugin is for http apps only with Director router. Make sure you do\n(Coffeescript):\n\n app.use flatiron.plugins.http\n\nor (in plain Javascript):\n\n app.use (flatiron.plugins.http);\n\nbefore you use this plugin. Thank you :)\n");
}
routes = {};
routes[options.path] = {
"/login": {
post: require("./login")
},
"/logout": {
post: require("./logout")
}
};
this.router.mount(routes);
return this.router.attach(function() {
var _base;
$ = debug("persona:attach:router-attach");
if (this.persona == null) {
this.persona = {};
}
return (_base = this.persona).audience != null ? (_base = this.persona).audience : _base.audience = options.audience;
});
},
detach: function() {},
init: function(done) {
var app;
$ = debug("persona:init");
app = this;
this.router.attach(function() {
var address, port, _base, _ref;
$ = debug("persona:init:router-attach");
_ref = app.server.address(), address = _ref.address, port = _ref.port;
if (this.persona == null) {
this.persona = {};
}
return (_base = this.persona).audience != null ? (_base = this.persona).audience : _base.audience = "http://" + address + ":" + port + "/";
});
return done();
}
};
}).call(this);
/*
//@ sourceMappingURL=index.map
*/