Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Feature/jwt auth (WIP) #76

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9d29e5f
feat: add jwt auth
eric-lara May 7, 2020
e740273
docs: add auth information to readme
eric-lara May 7, 2020
b3c603b
docs: add curl auth requests
eric-lara May 7, 2020
8d1ae61
chore: rebuild public folder
eric-lara May 18, 2020
1aa1846
Added aws-deployment and buildspec.yml for CodeBuild
dixonaws Aug 13, 2020
c84049b
adjusted name for buildspec.yml file
dixonaws Aug 13, 2020
a5f809c
updated buildspec.yml
dixonaws Aug 13, 2020
15d8a80
added aws-amplify dependency
dixonaws Aug 13, 2020
8585c20
updated buildspec.yml
dixonaws Aug 13, 2020
b744930
updated path to auth.service
dixonaws Aug 13, 2020
b1a4b39
adjusted files to support JWT tokens provided by Cognito
dixonaws Aug 13, 2020
001f9b0
adjusted files to support JWT tokens provided by Cognito
dixonaws Aug 13, 2020
59402a8
adjusted buildspec.yml to use environment variables
dixonaws Aug 13, 2020
0588e02
adjusted buildspec.yml to use environment variables
dixonaws Aug 13, 2020
93ce944
updated buildspec.yml to use environment variables
dixonaws Aug 13, 2020
0cc3ace
updated buildspec.yml to use environment variables
dixonaws Aug 13, 2020
7389e8b
updated buildspec.yml to use environment variables
dixonaws Aug 13, 2020
cceb140
updated client folder
dixonaws Aug 13, 2020
b523bd8
updated client folder
dixonaws Aug 13, 2020
9270849
updated swagger2.json
dixonaws Aug 13, 2020
451799b
adjusted buildspec.yaml with additonal environment variables
dixonaws Aug 14, 2020
991ce1e
removed original client directory
dixonaws Aug 14, 2020
24e202b
added uglify-js-plugin per https://github.com/amazon-archives/amazon-…
dixonaws Aug 14, 2020
8bd0ce8
added uglify-js-plugin per https://github.com/amazon-archives/amazon-…
dixonaws Aug 14, 2020
b982754
added uglify-js-plugin per https://github.com/amazon-archives/amazon-…
dixonaws Aug 14, 2020
cb12f7d
updates to CF template to pass variables to CodeBuild
dixonaws Aug 16, 2020
0d27bbd
added utilities to faciltate build
dixonaws Aug 16, 2020
f9f3a05
added utilities to faciltate build
dixonaws Aug 16, 2020
89acbd4
added utilities to faciltate build
dixonaws Aug 16, 2020
b469f79
added utilities to faciltate build
dixonaws Aug 16, 2020
ed34035
added utilities to faciltate build
dixonaws Aug 16, 2020
ae59745
Changes to buildspec.yml to copy build artifacts to s3
dixonaws Aug 16, 2020
b2b20e9
Changes to buildspec.yml to copy build artifacts to s3
dixonaws Aug 16, 2020
2e0c0e9
Changes to buildspec.yml to copy build artifacts to s3
dixonaws Aug 16, 2020
ae14ebe
Changes to buildspec.yml to copy build artifacts to s3
dixonaws Aug 16, 2020
ebdd427
Changes to buildspec.yml to copy build artifacts to s3
dixonaws Aug 16, 2020
9e6c3ad
Changes to buildspec.yml to copy build artifacts to s3
dixonaws Aug 16, 2020
98c9886
Changes to buildspec.yml to copy build artifacts to s3
dixonaws Aug 16, 2020
f7e4e3f
fix build error, use external UglifyJSPlugin
dixonaws Aug 16, 2020
2dbc708
updates to cloudformation template to deploy to the training_app_bucket
dixonaws Aug 16, 2020
cffd613
remove fix for webpack compile
dixonaws Aug 16, 2020
851de0e
added variables in cloudformation for source repo
dixonaws Aug 17, 2020
422b348
restrict IAM policies
dixonaws Aug 17, 2020
6c138fb
refactored cognito user admin to codebuild instead of lambda
dixonaws Aug 17, 2020
bcc5b18
use venv python interpreter as default
dixonaws Aug 17, 2020
b7c226c
added configure_cognito_user to build phase
dixonaws Aug 17, 2020
79dd09b
removed duplicate dependencies
dixonaws Aug 17, 2020
7bd19f2
added execution bit to python helper programs
dixonaws Aug 17, 2020
f5720fd
removed execution bit from python programs
dixonaws Aug 17, 2020
32e4223
removed artifact name from buildspec
dixonaws Aug 17, 2020
93869d7
specify a desired password when configuring cognito user
dixonaws Aug 17, 2020
2326fcc
new lambda function build
dixonaws Aug 17, 2020
6461649
download lambda package from codebuild artifact
dixonaws Aug 17, 2020
566776c
added custom resource to start build
dixonaws Aug 24, 2020
7d57a8c
updated buildspec to pass additional vars
dixonaws Aug 24, 2020
b6034ce
added vars
dixonaws Aug 24, 2020
9f91c88
removed temp files
dixonaws Aug 24, 2020
792a68e
minor fixes to cf template
dixonaws Aug 24, 2020
d4a2877
added variables to cf template
dixonaws Aug 24, 2020
7755f71
output server api package in base directory of training app bucket
dixonaws Aug 24, 2020
9ee105d
call start_build function with varialble for project
dixonaws Aug 24, 2020
8383dc1
added cloudformation resources
dixonaws Aug 25, 2020
91e8c01
removed start_build.zip package
dixonaws Aug 25, 2020
ae1ad28
verified swaggermiddleware
dixonaws Aug 25, 2020
e130b6a
logging to swaggermiddlware
dixonaws Aug 25, 2020
0f9d9b2
fix typo in config.js
dixonaws Aug 25, 2020
5b52400
added /api to end of basepath
dixonaws Aug 25, 2020
ddbcb0d
removed debug messages
dixonaws Aug 25, 2020
c8e8248
removed old cloudformation templates
dixonaws Aug 25, 2020
663e41c
Merge pull request #82 from dixonaws/feature/jwt-auth
Sep 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
node_modules
/client/build
mongo_data
aws-deployment/venv/
aws-deployment/venv3/

.env
.vscode
.idea
npm-debug.log

*.zip
venv3/
start_build.zip
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,75 @@ Example of multiple slot filling used in the same intent:

![Multiple slot filling](./screenshots/slot-filling-2.png)

## Auth

Added a jwt auth using [hapi-auth-jwt2](https://github.com/dwyl/hapi-auth-jwt2)

Auth endpoints:

/api/auth/register (POST with email & password fields) <-- foreign scope as default. To be able to login, admin needs to change it to 'collaborator'
```
curl -i 'http://localhost:3000/api/auth/register' \
-H 'Connection: keep-alive' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
-H 'Accept: application/json' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36' \
-H 'Content-Type: application/json' \
-H 'Origin: http://localhost:3000' \
-H 'Accept-Language: es-ES,es;q=0.9,en-US;q=0.8,en;q=0.7,ca-ES;q=0.6,ca;q=0.5' \
--data-binary '{"email":"[email protected]","password":"dummy-password"}' \
--compressed
```
/api/auth/login (POST with email & password fields)


```
curl 'http://localhost:3000/api/auth/login' \
-H 'Connection: keep-alive' \
-H 'Pragma: no-cache' \
-H 'Cache-Control: no-cache' \
-H 'Accept: application/json' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36' \
-H 'Content-Type: application/json' \
-H 'Origin: http://localhost:3000' \
-H 'Accept-Language: es-ES,es;q=0.9,en-US;q=0.8,en;q=0.7,ca-ES;q=0.6,ca;q=0.5' \
--data-binary '{"email":"[email protected]","password":"dummy-password"}' \
--compressed

```
Example of authenticated request:

```
curl -I -H "Authorization: <jwt token provided in login>" \
http://localhost:3000/api/intent/<intent id>

```

If you need to check some information inside token payload, you can access through request.auth field.

.env cfg
```
JWT_SECRET=
EXPIRY_TIME_SECONDS=
```

To modify scopes, check [Hapi documentation about scope](https://hapi.dev/api/?v=19.1.1#-serverauthapi) in the code, you can set scopes through feat files (server/feats/{resource}/{resource}.feat.js). Example:

```
...
add: {
method: 'POST',
path: '/intent',
description: 'Create a new instance of the model and persist it into the data source',
auth: { <-- auth cfg handled by Hapi
strategy: 'main',
scope: ['collaborator']
}
},
...
```

## Docker Compose

A docker-compose receipt is available to allow a quick-start easily. Just execute:
Expand Down
Loading