github.com/dbernstein1/tyk@v2.9.0-beta9-dl-apic+incompatible/middleware/ottoAuthExample.js (about)

     1  log("====> JS Auth initialising");
     2  
     3  var ottoAuthExample = new TykJS.TykMiddleware.NewMiddleware({});
     4  
     5  ottoAuthExample.NewProcessRequest(function(request, session) {
     6      log("----> Running ottoAuthExample JSVM Auth Middleware")
     7  
     8      var thisToken = request.Params["auth"];
     9  
    10      if (thisToken == undefined) {
    11          // no token at all?
    12          request.ReturnOverrides.ResponseCode = 401
    13          request.ReturnOverrides.ResponseError = 'Header missing (JS middleware)'
    14          return ottoAuthExample.ReturnData(request, {});
    15      }
    16  
    17      if (thisToken != "foobar") {
    18          request.ReturnOverrides.ResponseCode = 401
    19          request.ReturnOverrides.ResponseError = 'Not authorized (JS middleware)'
    20          return ottoAuthExample.ReturnData(request, {});
    21      }
    22  
    23      var thisSession = {
    24          "allowance": 100,
    25          "rate": 100,
    26          "per": 1,
    27          "quota_max": -1,
    28          "quota_renews": 1406121006,
    29          "access_rights": {}
    30      };
    31  
    32      return ottoAuthExample.ReturnAuthData(request, thisSession);
    33  });
    34  
    35  // Ensure init with a post-declaration log message
    36  log("====> JS Auth initialised");