-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.ts
27 lines (26 loc) · 1.06 KB
/
handler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import {CloudFrontRequestEvent} from 'aws-lambda';
import {Proxy} from "@mightyacorndigital/lambda-edge-proxy";
import {App} from "@octokit/app";
export function onViewerRequest(event: CloudFrontRequestEvent) {
const app = new App({
appId: process.env.GITHUB_APP_ID,
privateKey: process.env.GITHUB_PRIVATE_KEY,
oauth: {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
},
});
const handler = new Proxy(app.oauth, {
// Use a secure value for the hashKey. Ex: https://generate-secret.vercel.app/32
hashKey: process.env.HASH_KEY,
// This will be your publicly accessible domain.
baseUrl: 'http://localhost:8080',
scopes: ['user:email'],
async authorizer(token: string) {
// This is where you implement authorization logic, using the token to
// check whether the user meets your criteria for access. Throw an error
// to prevent access.
}
});
return handler.handleEvent(event);
}