aws-architect 6.6.48 → 6.6.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/template/package.json +2 -3
- package/bin/template/src/index.js +31 -29
- package/package.json +1 -1
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
"test": "mocha tests/**/*.js -R spec"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"authress-sdk": "^2.0.56",
|
|
17
18
|
"axios": "^0.21.4",
|
|
18
19
|
"ci-build-tools": "^1.0.13",
|
|
19
20
|
"fs-extra": "^7.0.1",
|
|
20
|
-
"jsonwebtoken": "^8.4.0",
|
|
21
|
-
"jwk-to-pem": "^2.0.0",
|
|
22
21
|
"microservice-utilities": "^0.1.121",
|
|
23
|
-
"openapi-factory": "^
|
|
22
|
+
"openapi-factory": "^5.3.48"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"aws-architect": "^6.5",
|
|
@@ -1,57 +1,59 @@
|
|
|
1
|
-
const aws = require('aws-sdk');
|
|
2
1
|
const Api = require('openapi-factory');
|
|
3
2
|
const path = require('path');
|
|
4
3
|
const fs = require('fs-extra');
|
|
5
|
-
const {
|
|
4
|
+
const { TokenVerifier } = require('authress-sdk');
|
|
6
5
|
|
|
7
|
-
let logger = new RequestLogger();
|
|
8
6
|
const api = new Api({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return request;
|
|
14
|
-
}
|
|
7
|
+
requestMiddleware(request) {
|
|
8
|
+
console.log(JSON.stringify({ title: 'RequestLogger', level: 'INFO', request: request }));
|
|
9
|
+
return request;
|
|
10
|
+
}
|
|
15
11
|
});
|
|
16
12
|
module.exports = api;
|
|
17
13
|
|
|
18
|
-
const authorizerConfiguration = { jwkKeyListUrl: 'https://authorization.domain.com/.well-known/jwks.json' };
|
|
19
|
-
let authorizer = new Authorizer(msg => logger.log(msg), authorizerConfiguration);
|
|
20
|
-
|
|
21
14
|
api.onEvent(trigger => {});
|
|
22
15
|
api.onSchedule(trigger => {});
|
|
23
16
|
|
|
24
|
-
api.setAuthorizer(request => {
|
|
25
|
-
|
|
17
|
+
api.setAuthorizer(async request => {
|
|
18
|
+
try {
|
|
19
|
+
const userToken = request.headers.Authorization.split(' ')[1];
|
|
20
|
+
// What should my url be? => https://authress.io/app/#/setup?focus=domain
|
|
21
|
+
// https://github.com/authress/authress-sdk.js
|
|
22
|
+
const userIdentity = await TokenVerifier('https://authorization.domain.com', userToken);
|
|
23
|
+
return userIdentity;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.log('User is unauthorized', error);
|
|
26
|
+
return { statusCode: 401 };
|
|
27
|
+
}
|
|
26
28
|
});
|
|
27
29
|
|
|
28
30
|
api.get('/.well-known/openapi.json', async () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
let openapiFile = path.join(__dirname, './openapi.json');
|
|
32
|
+
let data = await fs.readJson(openapiFile);
|
|
33
|
+
return { statusCode: 200, body: data };
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
api.get('/livecheck', () => {
|
|
35
|
-
|
|
37
|
+
return { statusCode: 200, body: { field: 'hello world' } };
|
|
36
38
|
});
|
|
37
39
|
|
|
38
40
|
api.get('/v1/resource/{resourceId}', request => {
|
|
39
|
-
|
|
41
|
+
return { statusCode: 200, body: { resourceId: request.pathParameters.resourceId }, headers: { 'Content-Type': 'application/json' } };
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
api.options('/{proxy+}', request => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
return {
|
|
46
|
+
statusCode: 200,
|
|
47
|
+
headers: {
|
|
48
|
+
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key',
|
|
49
|
+
'Access-Control-Allow-Methods': 'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT',
|
|
50
|
+
'Access-Control-Allow-Origin': request.headers.Origin || '*'
|
|
51
|
+
}
|
|
52
|
+
};
|
|
51
53
|
});
|
|
52
54
|
|
|
53
55
|
api.any('/{proxy+}', request => {
|
|
54
|
-
|
|
56
|
+
/*
|
|
55
57
|
{
|
|
56
58
|
request: {
|
|
57
59
|
"resource": "/{proxy+}",
|
|
@@ -84,5 +86,5 @@ api.any('/{proxy+}', request => {
|
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
*/
|
|
87
|
-
|
|
89
|
+
return { statusCode: 404 };
|
|
88
90
|
});
|