Skip to content

Commit ead49ed

Browse files
committed
First successful auth token
1 parent 5322fb0 commit ead49ed

File tree

15 files changed

+159
-112
lines changed

15 files changed

+159
-112
lines changed

site/_redirects

Lines changed: 0 additions & 2 deletions
This file was deleted.

site/public/index.html

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
1-
<!doctype html>
2-
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Hello, World!</title>
7-
</head>
8-
<body>
9-
<h1 id="heading"></h1>
10-
<p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
11-
<button id="button" type="button">Fetch a random UUID</button>
12-
<output id="random" for="button"></output>
13-
<script>
14-
fetch('/message')
15-
.then((resp) => resp.text())
16-
.then((text) => {
17-
const h1 = document.getElementById('heading');
18-
h1.textContent = text;
19-
});
1+
<html>
2+
3+
<head>
4+
<title>VGD Multi Library</title>
5+
<meta charset="utf-8" />
6+
</head>
7+
8+
<body>
9+
<h1>Welcome to the VGD Multi Library</h1>
10+
<a href="./oauth/initiate_twitch_oauth.html">Start Twitch OAuth</button>
11+
</body>
12+
13+
<script>console.log("This page loaded")</script>
2014

21-
const button = document.getElementById("button");
22-
button.addEventListener("click", () => {
23-
fetch('/random')
24-
.then((resp) => resp.text())
25-
.then((text) => {
26-
const random = document.getElementById('random');
27-
random.textContent = text;
28-
});
29-
});
30-
</script>
31-
</body>
3215
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<html>
2+
<head>
3+
<meta charset="utf-8">
4+
<title>Twitch OAuth</title>
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
</head>
7+
8+
<body>
9+
<h1>Click this to go to Twitch OAuth</h1>
10+
<button id="twitch-oauth-button">Start Twitch OAuth</button>
11+
</body>
12+
13+
14+
<script type="module">
15+
import startTwitchOAuth from "./initiate_twitch_oauth.js";
16+
17+
function initiateTwitchOAuth() {
18+
console.log("attempting twitch redirect");
19+
startTwitchOAuth();
20+
}
21+
22+
document.getElementById("twitch-oauth-button").addEventListener("click", () => {
23+
initiateTwitchOAuth();
24+
});
25+
26+
</script>
27+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
console.log("twitch oauth helper loaded")
2+
3+
function startTwitchOAuth() {
4+
fetch("/request_twitch_oauth_token")
5+
.then((resp) => resp.text())
6+
.then((text) => {
7+
console.log("Received a response: " + text);
8+
});
9+
}
10+
11+
export default startTwitchOAuth;

site/public/oauth/redirect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Unused for this flow

site/public/template_index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Hello, World!</title>
7+
</head>
8+
<body>
9+
<h1 id="heading"></h1>
10+
<p>This page comes from a static asset stored at `public/index.html` as configured in `wrangler.jsonc`.</p>
11+
<button id="button" type="button">Fetch a random UUID</button>
12+
<output id="random" for="button"></output>
13+
<script>
14+
fetch('/message')
15+
.then((resp) => resp.text())
16+
.then((text) => {
17+
const h1 = document.getElementById('heading');
18+
h1.textContent = text;
19+
});
20+
21+
const button = document.getElementById("button");
22+
button.addEventListener("click", () => {
23+
fetch('/random')
24+
.then((resp) => resp.text())
25+
.then((text) => {
26+
const random = document.getElementById('random');
27+
random.textContent = text;
28+
});
29+
});
30+
</script>
31+
</body>
32+
</html>

site/src/index.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

site/src/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
/**
2-
* Welcome to Cloudflare Workers! This is your first worker.
3-
*
4-
* - Run `npm run dev` in your terminal to start a development server
5-
* - Open a browser tab at http://localhost:8787/ to see your worker in action
6-
* - Run `npm run deploy` to publish your worker
7-
*
8-
* Learn more at https://developers.cloudflare.com/workers/
2+
* Docs: https://developers.cloudflare.com/workers/
93
*/
4+
import requestTwitchOauthToken from "./twitch_oauth/request_token";
105

116
export default {
127
async fetch(request, env, ctx) {
138
const url = new URL(request.url);
149
switch (url.pathname) {
10+
11+
case "/request_twitch_oauth_token":
12+
let token = await requestTwitchOauthToken(request, env, ctx);
13+
console.log("Got a response for twitch token");
14+
return new Response(token);
15+
1516
case '/message':
1617
return new Response('Hello, Worker!');
18+
1719
case '/random':
1820
return new Response(crypto.randomUUID());
21+
1922
default:
20-
return new Response('Not Found', { status: 404 });
23+
return new Response('Gorbldy', { status: 404 });
2124
}
2225
},
2326
};

site/src/oauth/initiate_twitch_oauth.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

site/src/oauth/initiate_twitch_oauth.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)