Permalink
Browse files

Customizable key in the session

Allow customization of the key used to store the email in
the session, defaulting to 'email' if not specified in
options. Option added in README.
  • Loading branch information...
1 parent 3b41a0b commit bafd35470b7c55f1774c2bf790e00baa37ab86a4 Mathieu Bruyen committed Jan 30, 2012
Showing with 7 additions and 2 deletions.
  1. +1 −0 README.md
  2. +6 −2 lib/express-browserid.js
View
@@ -84,6 +84,7 @@ the ones that make sense to them.
* audience. The scheme + host + optional port (e.g. `http://berjon.com` or `https://github.com:8001`) for which
this authentication is being made. Only override this if you know what you're doing, the client side is a better
place to configure this setting (if configured there, it will be used here).
+* sessionKey. The name of the key used to store the email in the session. Defaults to `email`.
## Interface (Client)
View
@@ -37,7 +37,7 @@ exports.plugVerifier = function (app, opts) {
var verifierResp = JSON.parse(body)
, valid = verifierResp && verifierResp.status === "okay"
, email = valid ? verifierResp.email : null;
- if (req.session) req.session.email = email;
+ if (req.session) req.session[getSessionKey(opts)] = email;
// if (valid) console.log("assertion verified successfully for email:", email);
// else console.log("failed to verify assertion:", verifierResp.reason);
if (valid) res.json({ status: "okay", email: email });
@@ -63,7 +63,7 @@ exports.plugLogout = function (app, opts) {
opts = opts || {};
var route = opts.logoutPath || makePath("/logout", opts);
app.all(route, function (req, res) {
- if (req.session) req.session.email = null;
+ if (req.session) req.session[getSessionKey(opts)] = null;
res.json(true);
});
};
@@ -72,3 +72,7 @@ function makePath (path, opts) {
var base = opts.basePath || "/browserid";
return base + path;
}
+
+function getSessionKey(opts) {
+ return opts.sessionKey || "email";
+}

0 comments on commit bafd354

Please sign in to comment.