Comparing version 0.0.12 to 0.0.13
//Authentication setup | ||
var CryptoJS = require('node-cryptojs-aes').CryptoJS; | ||
function matchPath(mask, path){ | ||
mask=mask.toLowerCase(); | ||
path=path.toLowerCase(); | ||
var maskArray=mask.split("/"); | ||
var pathArray=path.split("/"); | ||
if (maskArray.length!=pathArray.length) return false; | ||
for (var i= 0; i<maskArray.length; i++){ | ||
if ((maskArray[i]!="*") && (pathArray[i]!=maskArray[i])) return false; | ||
} | ||
return true; | ||
} | ||
//Check if route should be authorized | ||
function checkUrl(url, method, routes){ | ||
method=method.toLowerCase(); | ||
for (var i=0; i<routes.length; i++){ | ||
var route=routes[i]; | ||
if ((url==route.url) && (method==route.method)){ | ||
return true; | ||
} | ||
if ((matchPath(route.url,url)) && (method==route.method)) return true; | ||
} | ||
@@ -11,0 +23,0 @@ return false; |
{ | ||
"name": "bearer", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Bearer authentication module using token and Authorization HTTP header", | ||
@@ -5,0 +5,0 @@ "main": "bearer.js", |
@@ -15,3 +15,3 @@ BearerJS | ||
On your NodeJS app | ||
In your NodeJS app | ||
------------------ | ||
@@ -68,3 +68,4 @@ In your ExpressJS application init script, add the following before setting any other route. You will notice that you are free to create token content as you like. | ||
secureRoutes:[ | ||
{url:'/users', method:'get'} | ||
{url:'/secure', method:'get'}, | ||
{url:'/secure/*', method:'get'} | ||
] | ||
@@ -79,7 +80,7 @@ }); | ||
* createToken: Use this function to generate any token content you might need. Token will be encrypted and sent back as response from tokenURL request | ||
* validateToken: This method will provide you with decrypted token from request. Use it wizely to verify that it is ok | ||
* validateToken: This method will provide you with decrypted token from request. Use it wisely to verify that it is ok | ||
* onTokenValid: Sometimes you will not want to rely only on token validation. Once request is validated using token, you do additional check (perhaps check status in db etc.) | ||
* onAuthorized: In case you want to do something when request is authenticated (ex. log something) | ||
* onUnauthorized: In case that you want to do something when request is not authenticated | ||
* secureRoutes: Just add routes you want to have secured | ||
* secureRoutes: Just add routes you want to have secured. You can use "*" to define pattern | ||
@@ -95,3 +96,3 @@ Your TOKEN will be added to request and you can access it in any other action later. For example: | ||
On your Client app | ||
In your Client app | ||
------------------ | ||
@@ -98,0 +99,0 @@ You need to get your token first. Probably during application startup or login |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10665
109
116