-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic discord login process and minor
- Loading branch information
Showing
14 changed files
with
94 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/fileloader.ts | ||
framework/todo.md | ||
database/db.sqlite | ||
redbeansoup-v2.wiki/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// todo upgrade to rc45 | ||
// Important : See import maps to see all the dependencies. This file only export discordeno-related stuff. | ||
|
||
// discordeno lib | ||
export * from "https://deno.land/x/[email protected]rc31/mod.ts"; | ||
export * from "https://deno.land/x/[email protected]rc45/mod.ts"; | ||
|
||
// discordeno plugin | ||
export * from "https://deno.land/x/[email protected]rc31/plugins/mod.ts"; | ||
export * from "https://deno.land/x/[email protected]rc45/plugins/mod.ts"; | ||
|
||
// Terminal Colors! | ||
export * from "https://deno.land/[email protected]/fmt/colors.ts"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"imports": { | ||
"discordeno": "./deps/discordeno.ts", | ||
"denodb": "./deps/denodb.ts", | ||
"aqua": "./deps/aqua.ts", | ||
"denodb": "https://raw.githubusercontent.com/Aiko-Suzuki/denodb/master/mod.ts", | ||
"aqua": "https://deno.land/x/[email protected]/mod.ts", | ||
"discordeno": "./deps.ts", | ||
"config": "./config.ts", | ||
"framework/": "./framework/", | ||
"db": "./database/mod.ts" | ||
"db": "./database/mod.ts", | ||
"framework/": "./framework/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import env from "config"; | ||
|
||
export default class DiscordUtils { | ||
public static readonly oauthRedirectUrl = | ||
"https://discord.com/api/oauth2/authorize?client_id=942097556371021924&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Flogin&response_type=code&scope=identify%20guilds"; | ||
public static readonly redirectUri = "http://localhost:3000/api/login"; | ||
public static readonly API_ENDPOINT = "https://discord.com/api/v10"; | ||
|
||
static async exchangeCode(code: string) { | ||
const data = { | ||
client_id: env.CLIENT_ID, | ||
client_secret: env.CLIENT_SECRET, | ||
grant_type: "authorization_code", | ||
code: code, | ||
redirect_uri: DiscordUtils.redirectUri, | ||
}; | ||
const headers = { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}; | ||
const request = await fetch( | ||
DiscordUtils.API_ENDPOINT.concat("/oauth2/token"), | ||
{ | ||
headers: headers, | ||
method: "POST", | ||
body: new URLSearchParams(data).toString(), | ||
} | ||
); | ||
return await request.json(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import app from "../app.ts"; | ||
import { jsonResponse } from "../utils.ts"; | ||
import DiscordUtils from "./_discord.ts"; | ||
const oauthRedirectUrl = | ||
"https://discord.com/api/oauth2/authorize?client_id=942097556371021924&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fapi%2Flogin&response_type=code&scope=identify%20guilds"; | ||
|
||
app.get("/api/login", async (req) => { | ||
const { code } = req.query; | ||
if (!code) { | ||
return jsonResponse(400, { redirect: oauthRedirectUrl }); | ||
} | ||
const result = await DiscordUtils.exchangeCode(code); | ||
// const request = await fetch("https://discord.com/api/users/@me", { | ||
// headers: { | ||
// authorization: `${tokenType} ${accessToken}`, | ||
// }, | ||
// }); | ||
// const result = await request.json(); | ||
return jsonResponse(200, result); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import "./lore/[name].ts"; | ||
import "./login/index.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function jsonResponse( | ||
code: number, | ||
body: Record<string, unknown> | Array<unknown> | ||
) { | ||
return { | ||
statusCode: code, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
content: JSON.stringify(body), | ||
}; | ||
} |