Skip to content

Commit 315bd07

Browse files
committed
add mojang and minehut authentication
1 parent b5c6eb3 commit 315bd07

File tree

5 files changed

+17
-121
lines changed

5 files changed

+17
-121
lines changed

src/ab-test.ts

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

src/index.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
* Learn more at https://developers.cloudflare.com/workers/
99
*/
1010

11-
import handleProxy from './proxy';
12-
import handleRedirect from './redirect';
13-
import apiRouter from './router';
14-
1511
// Export a default object containing event handlers
1612
export default {
1713
// The fetch handler is invoked when this worker receives a HTTP(S) request
@@ -20,27 +16,26 @@ export default {
2016
// You'll find it helpful to parse the request.url string into a URL object. Learn more at https://developer.mozilla.org/en-US/docs/Web/API/URL
2117
const url = new URL(request.url);
2218

23-
// You can get pretty far with simple logic like if/switch-statements
24-
switch (url.pathname) {
25-
case '/redirect':
26-
return handleRedirect.fetch(request, env, ctx);
19+
if(url.pathname != "/mitm/session/minecraft/hasJoined") return new Response();
20+
21+
console.log(url.href);
2722

28-
case '/proxy':
29-
return handleProxy.fetch(request, env, ctx);
30-
}
3123

32-
if (url.pathname.startsWith('/api/')) {
33-
// You can also use more robust routing
34-
return apiRouter.handle(request);
24+
async function getAuthenticatedUser() {
25+
const newURLList = ["https://sessionserver.mojang.com/session/minecraft/hasJoined", "https://api.minehut.com/mitm/proxy/session/minecraft/hasJoined"];
26+
for (const newURL of newURLList) {
27+
const newRequestURL = newURL + url.search;
28+
const modifiedRequest = new Request(newRequestURL);
29+
const response = await fetch(modifiedRequest);
30+
if(response.status == 204) {
31+
continue;
32+
}
33+
return response;
34+
}
35+
//return page with no content
36+
return new Response(null, {status: 204});
3537
}
3638

37-
return new Response(
38-
`Try making requests to:
39-
<ul>
40-
<li><code><a href="/redirect?redirectUrl=https://example.com/">/redirect?redirectUrl=https://example.com/</a></code>,</li>
41-
<li><code><a href="/proxy?modify&proxyUrl=https://example.com/">/proxy?modify&proxyUrl=https://example.com/</a></code>, or</li>
42-
<li><code><a href="/api/todos">/api/todos</a></code></li>`,
43-
{ headers: { 'Content-Type': 'text/html' } }
44-
);
39+
return getAuthenticatedUser();
4540
},
4641
};

src/proxy.ts

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

src/redirect.ts

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

src/router.ts

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

0 commit comments

Comments
 (0)