-
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.
- Loading branch information
1 parent
a752012
commit 9f9a867
Showing
11 changed files
with
3,633 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["env"] | ||
} |
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,7 @@ | ||
# These are test credentials which are acceptable to be commited to version control | ||
AUTH0_DOMAIN=https://npm-authorizer.auth0.com/ | ||
AUTH0_CLIENT_ID=uUfz8vpypmgdhWMGd4meGA1k3feAJcPW | ||
AUTH0_CLIENT_SECRET=gllrc0F23XgNXkbVoR5CgIc8sQyPaqxTFOHIqrQYChR68YwakjLa1FWBvaYzNjxD | ||
AUTH0_AUDIENCE=https://test.npm-authorizer.com | ||
AUTH0_ALGORITHM=RS256 | ||
ENVIRONMENT=test |
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,42 @@ | ||
# Installation | ||
1. `npm install --save git+ssh://[email protected]/Vin65/npm-auth0-authorizer.git#master` | ||
|
||
2. Ensure the following environment variables are defined within your project: | ||
- AUTH0_DOMAIN (example: https://yourwebsite.auth0.com/) | ||
- AUTH0_AUDIENCE (The unique identifier of the target API you want to access.) | ||
- AUTH0_ALGORITHM (default: RS256) | ||
|
||
# Usage | ||
|
||
- handler.js | ||
|
||
```javascript | ||
import auth0Authorizer from 'npm-auth0-authorizer/methods/auth0Authorizer'; | ||
|
||
module.exports.auth0Authorizer = function(event, context, callback){ | ||
auth0Authorizer(event).then(success => { | ||
return callback(null, success); | ||
}).catch(err => { | ||
return callback(err); | ||
}); | ||
}; | ||
``` | ||
|
||
- serverless.yml | ||
|
||
```yaml | ||
functions: | ||
auth0Authorizer: | ||
handler: handler.auth0Authorizer | ||
lambdaYouWishToProtect: | ||
handler: handler.test | ||
events: | ||
- http: | ||
path: protect-me | ||
method: get | ||
integration: lambda | ||
authorizer: | ||
name: auth0Authorizer | ||
resultTtlInSeconds: 0 | ||
identitySource: method.request.header.Authorization | ||
``` |
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,22 @@ | ||
'use strict'; | ||
|
||
const request = require('request-promise'); | ||
|
||
var utilities = { | ||
isString: function(obj) { | ||
return (typeof obj === 'string' || obj instanceof String); | ||
}, | ||
parseJSON: function(string) { | ||
return this.isString(string) ? JSON.parse(string) : string; | ||
}, | ||
httpRequest: function(options) { | ||
return request(options).then(response => { | ||
return response; | ||
}).catch(err => { | ||
console.error(err.body); | ||
return err; | ||
}); | ||
} | ||
} | ||
|
||
module.exports = utilities; |
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
Oops, something went wrong.