Skip to content

Commit

Permalink
include binaries for the release
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyzzz committed Jun 16, 2020
1 parent ce7ec7e commit a4c72a4
Show file tree
Hide file tree
Showing 89 changed files with 9,786 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lambda-release/lambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const jwt = require('jsonwebtoken');
const { CLIENT_SECRET } = require('./template');

function parseToken(headers) {
//see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html
const {authorization = []} = headers;
if (authorization.length > 0) {
for (let i = 0; i < authorization.length; i++) {
const token = authorization[i].value || ''
const prefix = 'Bearer ';
if (token.startsWith(prefix)) {
return token.substring(prefix.length)
}
}
}

return null;
}

function checkToken(token) {
if (!token) return false

try {
const payload = jwt.verify(token, CLIENT_SECRET, {algorithm: ['RS512']});
if (payload.orgDomain !== 'jetbrains') {
console.log('orgDomain is not correct:',JSON.stringify(payload))
return false
}
return true
} catch (e) {
// token exists but it-is invalid
console.log('Failed to verify token', e);
}
return false;
}

function handler(request, callback) {
const token = parseToken(request.headers);
if (checkToken(token)) {
callback(null, request);
} else {
callback(null, {
status: '403',
body: JSON.stringify({
message: 'Unauthorized'
})
});
}
}

exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
handler(request, callback)
};
160 changes: 160 additions & 0 deletions lambda-release/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lambda-release/node_modules/buffer-equal-constant-time/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions lambda-release/node_modules/buffer-equal-constant-time/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions lambda-release/node_modules/buffer-equal-constant-time/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a4c72a4

Please sign in to comment.