summaryrefslogtreecommitdiff
path: root/fig-frontend/client/src/twitch.ts
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-03-01 18:39:11 -0500
committerLLLL Colonq <llll@colonq>2024-03-01 18:39:11 -0500
commit88e2726fc1fc6cec2b9e63526ce4c0a1a04a2e98 (patch)
tree94fd56c8c02e422a54d69aa7dec798b7a55d6a2d /fig-frontend/client/src/twitch.ts
parent4a23754fc6515c947e0bbac38cd0e558b701fe2f (diff)
Add new frontend
Diffstat (limited to 'fig-frontend/client/src/twitch.ts')
-rw-r--r--fig-frontend/client/src/twitch.ts43
1 files changed, 0 insertions, 43 deletions
diff --git a/fig-frontend/client/src/twitch.ts b/fig-frontend/client/src/twitch.ts
deleted file mode 100644
index 4c264be..0000000
--- a/fig-frontend/client/src/twitch.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-import * as Config from "./config";
-
-function generateNonce(): string {
- var arr = new Uint8Array(20);
- window.crypto.getRandomValues(arr);
- return Array.from(arr, b => b.toString(16).padStart(2, "0")).join("");
-}
-
-export function startTwitchAuth() {
- const nonce = generateNonce();
- document.cookie = `authnonce=${nonce}; path=/;`;
- window.location.href =
- `https://id.twitch.tv/oauth2/authorize?response_type=id_token`
- + `&client_id=${Config.CLIENT_ID}`
- + `&redirect_uri=${Config.URL}`
- + `&scope=openid`
- + `&nonce=${nonce}`
- + `&claims=${{id_token: {preferred_username: null}}}`
- ;
-}
-
-export function getFragmentQuery(): Map<string, string> {
- let query = new Map();
- const hashQuery = document.location.hash.slice(1).split("&");
- for (let equals of hashQuery) {
- const pair = equals.split("=");
- query.set(decodeURIComponent(pair[0]), decodeURIComponent(pair[1]));
- }
- return query;
-}
-
-export function getAuthToken(): String | null {
- const frag = getFragmentQuery();
- const token = frag.get("id_token");
- if (token) {
- document.cookie = `id_token=${token}; path=/; SameSite=Strict`;
- }
- for (let c of document.cookie.split("; ")) {
- const [k, v] = c.split("=");
- if (k === "id_token") return v;
- }
- return null;
-}