ewd-session
Advanced tools
Comparing version 2.11.0 to 2.12.0
@@ -6,3 +6,3 @@ /* | ||
| | | ||
| Copyright (c) 2016 M/Gateway Developments Ltd, | | ||
| Copyright (c) 2016-17 M/Gateway Developments Ltd, | | ||
| Reigate, Surrey UK. | | ||
@@ -28,3 +28,3 @@ | All rights reserved. | | ||
7 December 2016 | ||
20 March 2017 | ||
@@ -222,2 +222,48 @@ */ | ||
function httpAuthenticate(httpHeaders, credentials) { | ||
var cookie = httpHeaders.cookie; | ||
var authorization = httpHeaders.authorization; | ||
if (!cookie && !authorization) { | ||
return { | ||
error: 'Missing Authorization or Cookie Header', | ||
status: { | ||
code: 403, | ||
text: 'Forbidden' | ||
} | ||
}; | ||
} | ||
var credentials = credentials || { | ||
authorization: 'QEWD token', | ||
cookie: 'QEWDTOKEN' | ||
}; | ||
var token; | ||
if (authorization) { | ||
// authorization, if present, over-rides cookie | ||
token = authorization.split(credentials.authorization + '=')[1]; | ||
} | ||
else { | ||
var pieces = cookie.split(';'); | ||
pieces.forEach(function(piece) { | ||
if (piece.indexOf(credentials.cookie) !== -1) { | ||
token = piece.split(credentials.cookie + '=')[1]; | ||
} | ||
}); | ||
} | ||
if (!token || token === '') { | ||
return { | ||
error: 'Missing or Empty QEWD Session Token', | ||
status: { | ||
code: 403, | ||
text: 'Forbidden' | ||
} | ||
}; | ||
} | ||
return tokenAuthenticate(token, 'noCheck'); | ||
} | ||
function getActiveSessions() { | ||
@@ -250,4 +296,5 @@ var sessions = []; | ||
authenticate: tokenAuthenticate, | ||
httpAuthenticate: httpAuthenticate, | ||
active: getActiveSessions, | ||
byToken: getSessionByToken | ||
}; |
{ | ||
"name": "ewd-session", | ||
"version": "2.11.0", | ||
"version": "2.12.0", | ||
"description": "Session management using ewd-document-store DocumentNodes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
76559
1113