forked from TykTechnologies/tyk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JS Middleware auth plgin support
- Loading branch information
1 parent
1874df1
commit a91e081
Showing
5 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
log("====> JS Auth initialising"); | ||
|
||
var OttoAuthExample = new TykJS.TykMiddleware.NewMiddleware({}); | ||
|
||
OttoAuthExample.NewProcessRequest(function(request, session) { | ||
log("----> Running OttoAuthExample JSVM Auth Middleware") | ||
|
||
var thisToken = request.Params["auth"]; | ||
|
||
if (thisToken == undefined) { | ||
// no token at all? | ||
request.ReturnOverrides.ResponseCode = 401 | ||
request.ReturnOverrides.ResponseError = 'Header missing (JS middleware)' | ||
return OttoAuthExample.ReturnData(request, {}); | ||
} | ||
|
||
if (thisToken != "foobar") { | ||
request.ReturnOverrides.ResponseCode = 401 | ||
request.ReturnOverrides.ResponseError = 'Not authorized (JS middleware)' | ||
return OttoAuthExample.ReturnData(request, {}); | ||
} | ||
|
||
var thisSession = { | ||
"allowance": 100, | ||
"rate": 100, | ||
"per": 1, | ||
"quota_max": -1, | ||
"quota_renews": 1406121006, | ||
"access_rights": {} | ||
}; | ||
|
||
return OttoAuthExample.ReturnAuthData(request, thisSession); | ||
}); | ||
|
||
// Ensure init with a post-declaration log message | ||
log("====> JS Auth initialised"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters