Permalink
Browse files

added @Auth (connect-auth integration)

  • Loading branch information...
1 parent 0fc7277 commit 870f6f2c59ec5710a23dfd2f188f79368d466bdb @warmuuh committed Apr 10, 2013
Showing with 48 additions and 7 deletions.
  1. +1 −1 node-example/package.json
  2. +47 −6 yaap/wire/express/plugins/VerbProcessors.js
@@ -14,7 +14,7 @@
"Peter Mucha <ptmucha@gmail.com>"
],
"dependencies": {
- "yaap": "0.0.1",
+ "yaap": "0.0.4",
"wire": "0.9.1"
},
"license": "MIT",
@@ -31,8 +31,15 @@ function(when, _) {
path = obj["@Path"] + path;
console.log("Registering route: " + path);
+
+ var authFn = null;
+
+ try{authFn = getAuthentification(fnDescription)}
+ catch(e){console.log(e)}
- fnExpress(path, function(req, res, next){
+ fnExpress(path, authFn, function(req, res, next){
+
+
var responseSent = false;
var sendResponse = function(result){
responseSent = true;
@@ -51,6 +58,36 @@ function(when, _) {
}
+ function getAuthentification(fnDescription){
+ var useAuth = (getAnnotation(fnDescription, "@Auth") !== undefined);
+
+ var authFn = function(req, res, next){next()};
+ if (useAuth)
+ authFn = function(req, res, next)
+ {
+ if (req.isAuthenticated === undefined){
+ console.error("connect-auth is missing");
+ next();
+ }
+ if (!req.isAuthenticated())
+ {
+ req.authenticate(function(err, succ){
+ if (err) console.log(err);
+ next();
+ });
+ return;
+ }
+ else{
+ next();
+ }
+ };
+
+
+ return authFn;
+
+ }
+
+
function processParameters(req, fnDescription, responseCallback){
var args = [];
@@ -60,11 +97,9 @@ function(when, _) {
//handle @Param
var annoParam = getAnnotation(param, "@Param");
- var annoBody = getAnnotation(param, "@Body");
- var cb = getAnnotation(param, "@Callback");
- if ((processEveryParameter && annoBody === undefined && cb === undefined) //NO other annotations allowed because it would be overwritten
+ if ((processEveryParameter && param.annotations.length == 0) //NO other annotations allowed because it would be overwritten
|| (annoParam !== undefined))
{
var parameterName = param.name;
@@ -74,13 +109,19 @@ function(when, _) {
}
//handle @Body
- if (annoBody !== undefined)
+ if ( getAnnotation(param, "@Body") !== undefined)
{
args[param.index] = req.body;
}
+ //handle @Body
+ if ( getAnnotation(param, "@Session") !== undefined)
+ {
+ args[param.index] = req.session;
+ }
+
//handle @Callback
- if (cb !== undefined)
+ if (getAnnotation(param, "@Callback") !== undefined)
{
args[param.index] = responseCallback;
}

0 comments on commit 870f6f2

Please sign in to comment.