-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitch-ext.js
39 lines (33 loc) · 1.2 KB
/
twitch-ext.js
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
28
29
30
31
32
33
34
35
36
37
38
39
import { verify, decode } from "https://deno.land/x/[email protected]/mod.ts";
import * as djwt from "https://deno.land/x/[email protected]/mod.ts";
import {
encodeBase64,
decodeBase64,
} from "https://deno.land/[email protected]/encoding/base64.ts"
import { Database } from "./database.js";
// =========================================
const key = await Database.get("twitch_ext_secret");
const jwt = decodeBase64(key);
const bearerPrefix = 'Bearer ';
export async function verifyAndDecode (header) {
if(!header){
return console.log("No Auth!");
}
if (header.startsWith(bearerPrefix)) {
try {
const token = header.substring(bearerPrefix.length);
return await verify(jwt, key);
}
catch (ex) {
return console.log("Invalid JWT");
}
}
}
// export function extMiddle(req, res, next) {
// res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With');
// res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET, POST');
// // Note that the origin of an extension iframe will be null
// // so the Access-Control-Allow-Origin has to be wildcard.
// res.setHeader('Access-Control-Allow-Origin', '*');
// next();
// };