diff --git a/lib/serve.js b/lib/serve.js index 1420bdbd..23b46efa 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -4,6 +4,7 @@ var expressLogging = require("express-logging"); var queryString = require("querystring"); var path = require("path"); var conf = require("./config"); +var jwtDecode = require("jwt-decode") function handleErr(err, response) { response.statusCode = 500; @@ -76,7 +77,17 @@ function createHandler(dir, static) { }; var callback = createCallback(response); - var promise = handler.handler(lambdaRequest, {}, callback); + let clientContext = {} + if (request.headers['authorization']) { + const parts = request.headers['authorization'].split(' ') + if (parts.length === 2 && parts[0] === 'Bearer') { + clientContext = { + identity: { url: '', token: '' }, + user: jwtDecode(parts[1]) + } + } + } + var promise = handler.handler(lambdaRequest, { clientContext }, callback); promiseCallback(promise, callback); }; } diff --git a/package.json b/package.json index ad748bd2..794ec64b 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "commander": "^2.17.1", "express": "^4.16.3", "express-logging": "^1.1.1", + "jwt-decode": "^2.2.0", "toml": "^2.3.3", "webpack": "^4.17.1", "webpack-merge": "^4.1.4" diff --git a/yarn.lock b/yarn.lock index 1a0ca5d7..74d6ae02 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2040,6 +2040,23 @@ json5@^0.5.0: version "0.5.1" resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" +jsonify@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" + +jsprim@^1.2.2: + version "1.4.1" + resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" + dependencies: + assert-plus "1.0.0" + extsprintf "1.3.0" + json-schema "0.2.3" + verror "1.10.0" + +jwt-decode@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-2.2.0.tgz#7d86bd56679f58ce6a84704a657dd392bba81a79" + kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0: version "3.2.2" resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"