How to monkey patch request obj with data in express/connect

Helllo Im programming a middleware library to abstract the process of oauth authorize/authenticate and supply own authentication strategies.

I'm stuck because when I monkey patch the request with data it won't be available on any routed request but the other middlewares (connect/express documentation is very poor on this subject).

How can I make the data stick so it would be available to every request (except for static files)?

Thanks.

P.s I don't use other available modules because it was just frustrating to make them work...

-------------Problems Reply------------

Try this:

function authOrDie() {
return function(req,res,next) {
console.log(req.isAuthenticated());
next(); // Have to call next to continue to the next middleware
};
}

I assume console.log(req.isAuthenticated()); is being run and it's working, I also assume it's printing false.

Also, if requests to your static files doesn't need to be authenticated you should move it much higher in the stack.

Category:node.js Views:0 Time:2011-09-14

Related post

  • Monkey patching R language base functions with big data functions for speed 2011-03-12

    It all started with an R package I needed to use badly ('nlt'), which has 2 other (quite large) package dependencies ('adlift', 'ebayesthresh'). I needed it to analyze a data sample of about 4000 points. The algorithms create many 'hidden' vectors, s

  • Monkey Patch Date class the best option? 2011-06-17

    In my app, I want to support a blank date field as meaning "some indefinite date in the future", both upon entry and viewing. Since I'm storing this in the database and nil sorts before any non-nil date, I decided to monkey-patch the Date class to im

  • Monkey-patch Date class for next_ methods 2012-04-30

    In my Rails app I need to get the dates for the next occurrence of a particular weekday starting from some other date. So basically I need date.next_monday, date.next_wednesday type functions. I don't think these exist in standard Ruby libraries so I

  • Can you monkey patch methods on core types in python? 2008-10-10

    Ruby can add methods to the Number class and other core types to get effects like: 1.should_equal(1) But it seems like python cannot do this. Is this true? And if so, why? Does it have something to do with the fact that type can't be modified? Update

  • monkey patching in php 2012-04-08

    I'm trying to figure out how monkey patching works and how i can make it work on my own objects/methods. I've been looking at this lib, it does exactly what i want to do myself: https://github.com/antecedent/patchwork With it you can redefine a metho

  • How can I monkey-patch an instance method in Perl? 2009-01-16

    I'm trying to monkey-patch (duck-punch :-) a LWP::UserAgent instance, like so: sub _user_agent_get_basic_credentials_patch { return ($username, $password); } my $agent = LWP::UserAgent->new(); $agent->get_basic_credentials = _user_agent_get_bas

  • Do any "major" frameworks make use of monkey-patching/open classes 2009-05-20

    I am curious about the usage of the feature known as open classes or monkey-patching in languages like e.g. Ruby, Python, Groovy etc. This feature allows you to make modifications (like adding or replacing methods) to existing classes or objects at r

  • How to implement monkey patch in C++? 2009-10-18

    Is it possible to implement monkey patching in C++? Or any other similar approach to that? Thanks. --------------Solutions------------- Not portably so, and due to the dangers for larger projects you better have good reason. The Preprocessor is proba

  • How to monkey-patch code that gets auto-loaded in Rails? 2010-12-16

    I'm monkey-patching a Rails engine with something like: SomeClass.class_eval do # ... end The first time I hit the web site, on development mode at least, it works, but the second time it's like my patch never existed. I presume it's Rails auto-reloa

  • What is monkey patch? 2011-04-11

    I am trying to understand this definition. Is that something like methods/operators overloading or delegating? Does it have anything common with these things? --------------Solutions------------- No, it's not like any of those things. It's simply the

  • Is it possible to give javascript partial class behavior like C# or monkey patching like Ruby does? 2011-05-14

    The idea behind partial classes is that you can group certain functions together. The best example of this in C# is putting control definitions in one file and the event handlers in another. In Ruby, you can use Monkey patching to replace entire func

  • How does extending classes (Monkey Patching) work in Python? 2011-06-08

    class Foo(object): pass foo = Foo() def bar(self): print 'bar' Foo.bar = bar foo.bar() #bar Coming from JavaScript, if a "class" prototype was augmented with a certain attribute. It is known that all instances of that "class" would have that attribut

  • How to monkey patch Django? 2011-07-16

    I came upon this post on monkey patching Django: from django.contrib.auth.models import User User.add_to_class('openid', models.CharField(max_length=250,blank=True)) def get_user_name(self): if self.first_name or self.last_name: return self.first_nam

  • How do I monkey patch an object's constructor function? 2011-12-16

    I'd like to monkey patch the constructor for this 'Controller' object. But how do I monkey patch the constructor function so I can still call the original? This is what I've tried. // original function Controller() { this._tag = 'div'; } Controller.p

  • Cannot override/monkey patch a rails method with rails 3.1.3 2012-03-11

    I am trying to override an active resource method like explained in this question : Remove .xml extension from ActiveResource request and this one : i want to use a REST api, i cannot manage to set active resource to use it To do so i tested : Creati

  • Adding methods to a sudsobject. Monkey patching or import to new object? 2012-03-16

    I an writing some python code that uses suds to connect up to a device, get the wsdl and query for some device information. That part of the code works and it looks like suds creates and objects and places the data in that object. I would like to add

  • Monkey patch flex framework when loaded as an RSL? 2008-10-17

    I want to load the flex framework as an RSL (SWZ, using player caching) but I need to monkey patch a couple of bug fixes in the framework. A number of forums suggest this is not possible. Has anyone gotten this to work? --------------Solutions-------

  • Monkey-patching Vs. S.O.L.I.D. principles? 2008-11-15

    I'm slowly moving from PHP5 to Python on some personal projects, and I'm currently loving the experience. Before choosing to go down the Python route I looked at Ruby. What I did notice from the ruby community was that monkey-patching was both common

  • How do you detect that monkey patching has occurred in Ruby? 2008-12-02

    How do you check that monkey patching has been done to a specific class in Ruby? If that is possible, is it also possible to get the previous implementation(s) of the attribute that's been patched? --------------Solutions------------- There are the h

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.204 (s). 11 q(s)