From d138b2b8426904e66b79e3ddee3492cbc80d0b16 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 26 Jun 2022 23:14:10 +1000 Subject: [PATCH] Start of custom login and discord oauth flow --- fosscord-server.code-workspace | 7 ++- slowcord/.env.template | 5 ++ slowcord/.vscode/launch.json | 14 +++++ slowcord/.vscode/tasks.json | 13 +++++ slowcord/README.md | 1 + slowcord/build/index.js | 102 ++++++++++++++++++++++++++++++++ slowcord/build/index.js.map | 1 + slowcord/package-lock.json | Bin 0 -> 51373 bytes slowcord/package.json | 33 +++++++++++ slowcord/public/login.html | 65 +++++++++++++++++++++ slowcord/src/index.ts | 104 +++++++++++++++++++++++++++++++++ slowcord/tsconfig.json | 99 +++++++++++++++++++++++++++++++ util/src/entities/Channel.ts | 1 + util/src/util/Event.ts | 1 + 14 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 slowcord/.env.template create mode 100644 slowcord/.vscode/launch.json create mode 100644 slowcord/.vscode/tasks.json create mode 100644 slowcord/README.md create mode 100644 slowcord/build/index.js create mode 100644 slowcord/build/index.js.map create mode 100644 slowcord/package-lock.json create mode 100644 slowcord/package.json create mode 100644 slowcord/public/login.html create mode 100644 slowcord/src/index.ts create mode 100644 slowcord/tsconfig.json diff --git a/fosscord-server.code-workspace b/fosscord-server.code-workspace index e618b7f0..cd060713 100644 --- a/fosscord-server.code-workspace +++ b/fosscord-server.code-workspace @@ -23,7 +23,12 @@ }, { "path": "webrtc" + }, + { + "path": "slowcord" } ], - "settings": {} + "settings": { + "typescript.tsdk": "util\\node_modules\\typescript\\lib" + } } diff --git a/slowcord/.env.template b/slowcord/.env.template new file mode 100644 index 00000000..34f6abeb --- /dev/null +++ b/slowcord/.env.template @@ -0,0 +1,5 @@ +DATABASE=../bundle/database.db +PORT=3010 +DISCORD_CLIENT_ID= +DISCORD_SECRET= +DISCORD_REDIRECT= \ No newline at end of file diff --git a/slowcord/.vscode/launch.json b/slowcord/.vscode/launch.json new file mode 100644 index 00000000..0467baec --- /dev/null +++ b/slowcord/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + "configurations": [ + { + "name": "Launch Program", + "program": "${workspaceFolder}/build/index.js", + "request": "launch", + "skipFiles": [ + "/**" + ], + "type": "node", + "preLaunchTask": "tsc: build - tsconfig.json" + } + ] +} \ No newline at end of file diff --git a/slowcord/.vscode/tasks.json b/slowcord/.vscode/tasks.json new file mode 100644 index 00000000..356126d8 --- /dev/null +++ b/slowcord/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "build", + "group": "build", + "problemMatcher": [], + "label": "npm: build", + "detail": "tsc -b" + } + ] +} \ No newline at end of file diff --git a/slowcord/README.md b/slowcord/README.md new file mode 100644 index 00000000..629e7724 --- /dev/null +++ b/slowcord/README.md @@ -0,0 +1 @@ +Additional resources/services for [Slowcord](slowcord.maddy.k.vu) \ No newline at end of file diff --git a/slowcord/build/index.js b/slowcord/build/index.js new file mode 100644 index 00000000..484113ed --- /dev/null +++ b/slowcord/build/index.js @@ -0,0 +1,102 @@ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var _a; +import "dotenv/config"; +import express from "express"; +import cookieParser from "cookie-parser"; +import { initDatabase, generateToken, User, Config } from "@fosscord/util"; +import path from "path"; +import fetch from "node-fetch"; +const app = express(); +app.use(cookieParser()); +const port = process.env.PORT; +class Discord { +} +_a = Discord; +Discord.getAccessToken = (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const { code } = req.query; + const body = new URLSearchParams(Object.entries({ + client_id: process.env.DISCORD_CLIENT_ID, + client_secret: process.env.DISCORD_SECRET, + redirect_uri: process.env.DISCORD_REDIRECT, + code: code, + grant_type: "authorization_code", + })).toString(); + const resp = yield fetch("https://discord.com/api/oauth2/token", { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: body + }); + const json = yield resp.json(); + if (json.error) + return null; + return { + access_token: json.access_token, + token_type: json.token_type, + expires_in: json.expires_in, + refresh_token: json.refresh_token, + scope: json.scope, + }; +}); +Discord.getUserDetails = (token) => __awaiter(void 0, void 0, void 0, function* () { + const resp = yield fetch("https://discord.com/api/users/@me", { + headers: { + "Authorization": `Bearer ${token}`, + } + }); + const json = yield resp.json(); + if (!json.username || !json.email) + return null; // eh, deal with bad code later + return { + email: json.email, + username: json.username, + }; +}); +const handlers = { + "discord": Discord, +}; +app.get("/oauth/:type", (req, res) => __awaiter(void 0, void 0, void 0, function* () { + const { type } = req.params; + if (!type) + return res.sendStatus(400); + const handler = handlers[type]; + if (!handler) + return res.sendStatus(400); + const data = yield handler.getAccessToken(req, res); + if (!data) + return res.sendStatus(500); + const details = yield handler.getUserDetails(data.access_token); + if (!details) + return res.sendStatus(500); + let user = yield User.findOne({ where: { email: details.email } }); + if (!user) { + user = yield User.register({ + email: details.email, + username: details.username, + req + }); + } + const token = yield generateToken(user.id); + res.cookie("token", token); + res.sendFile(path.join(__dirname, "../public/login.html")); +})); +app.get("*", (req, res) => { + res.sendFile(path.join(__dirname, "../public/login.html")); +}); +(() => __awaiter(void 0, void 0, void 0, function* () { + yield initDatabase(); + yield Config.init(); + app.listen(port, () => { + console.log(`Listening on port ${port}`); + }); +}))(); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/slowcord/build/index.js.map b/slowcord/build/index.js.map new file mode 100644 index 00000000..ca656f86 --- /dev/null +++ b/slowcord/build/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],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json b/slowcord/package-lock.json new file mode 100644 index 0000000000000000000000000000000000000000..7ec24a87946c548453ad8a250a7cc4be5af3decc GIT binary patch literal 51373 zcmeHw>679}lJDo5zhbODE-zD@0><7xTX6`)B?-j2_WGGFgg_TMfj$2A=OI86DJ4fu zXLoJQSXp1W^%eU_augl;6_Sf%@W(J~ZOW*$&eCW%zqnZZ#yzriX z&xapsrnp-XQv?}b`? z$1o-NZ7sXvCcIgCF9JFAp8s`yTfde4!tT+M9W48eO4kSf+xc4`o?m@0eEbG_kMoPy z!kG(S0sa@h#`h}>A1CAkYUfw}WLh@7Lm7_CYuZG#Rm+8^T_*lV=Zx3)mZl2fYv#<`djV263>Rl>w;{%Z!o(siZdQCBZcCX zvaULgYAA08@2bB1wsqdto*}xx^ykSfpl{crZ+n^>ktx4Nn17gbnDY1N2^J5$02~&I zLih$auvqm<(o(|DYVR|psKW*c>mh(3Zvt>nfT>JQLSo+p^H*E#GfRdn$y8O7V<&Qu?DCc{~AZddVw$(oHr(CP4aYg{o4t!7>M*MGe{Qj(D(jy23DYX1z9 zXc`6x0(!fD$(Z`{=ON49#X2UF!np+EQL0?t?KPY)Q~~45Z?K{vVh`{YC3$)D%l*08 zR;&g!;SO_uzjS8Da=F~1_wq(1OY33DkPCT2@8QMq1n{34hhcBgW#?m-T@>YUy{uP` z1!{F{1&!^jPO?9S?^O`~0SDBxP4`vBDDe$o%f zKwfXl%xP6IFg4&M;QgSu;hLK~sf`GEK5*G#sYhU=1*R@}g|gVCo=&mdka2;5DHMJy{8jK=-eDJi>+x@%Y(J!Y)ozO?q{yMrOFMg?0I3b<4;YR3&*%O9$Lw=%ly z>hDgO%^ON`$N!9|>1t>krDmr9`sK21cyVqJMVJQk1N0QK67DaqOM*Mh4$62x>f%PX zO*y`T?}`mmEcCimeI;}&>YOBfY{>1z&8Z|5RJqgQD_owhk59%(qVoOCOpt{6WR&aA z=Qg_UDM z{DEj@>6yDogz6xL1O8sW?(ARWhrI(J?47re!UF`z4qqVgBFW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!rV lvhZaUuA>qEigl`^!F`e$pW@$Nx!yDa1IkGM<-h*&{{bloUeEvl literal 0 HcmV?d00001 diff --git a/slowcord/package.json b/slowcord/package.json new file mode 100644 index 00000000..9a64c2b3 --- /dev/null +++ b/slowcord/package.json @@ -0,0 +1,33 @@ +{ + "name": "slowcord", + "version": "1.0.0", + "description": "Slowcord additional services", + "main": "build/index.js", + "scripts": { + "build": "tsc -b", + "run": "node build/index.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/maddyunderstars/fosscord-server.git" + }, + "author": "", + "license": "AGPL-3.0-only", + "bugs": { + "url": "https://github.com/maddyunderstars/fosscord-server/issues" + }, + "homepage": "https://github.com/maddyunderstars/fosscord-server#readme", + "dependencies": { + "@fosscord/util": "file:../util", + "cookie-parser": "^1.4.6", + "dotenv": "^16.0.1", + "express": "^4.18.1", + "node-fetch": "^3.2.6" + }, + "devDependencies": { + "@types/cookie-parser": "^1.4.3", + "@types/express": "^4.17.13", + "@types/node": "^18.0.0" + }, + "type": "module" +} diff --git a/slowcord/public/login.html b/slowcord/public/login.html new file mode 100644 index 00000000..a695e597 --- /dev/null +++ b/slowcord/public/login.html @@ -0,0 +1,65 @@ + + + + + + + Slowcord + + + +
+
+ + + + + + Login with Discord + +
+
+ + + + + \ No newline at end of file diff --git a/slowcord/src/index.ts b/slowcord/src/index.ts new file mode 100644 index 00000000..3d397aaf --- /dev/null +++ b/slowcord/src/index.ts @@ -0,0 +1,104 @@ +import "dotenv/config"; +import express, { Request, Response } from "express"; +import cookieParser from "cookie-parser"; +import { initDatabase, generateToken, User, Config } from "@fosscord/util"; +import path from "path"; +import fetch from "node-fetch"; + +const app = express(); +app.use(cookieParser()); +const port = process.env.PORT; + +class Discord { + static getAccessToken = async (req: Request, res: Response) => { + const { code } = req.query; + + const body = new URLSearchParams(Object.entries({ + client_id: process.env.DISCORD_CLIENT_ID as string, + client_secret: process.env.DISCORD_SECRET as string, + redirect_uri: process.env.DISCORD_REDIRECT as string, + code: code as string, + grant_type: "authorization_code", + })).toString(); + + const resp = await fetch("https://discord.com/api/oauth2/token", { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: body + }); + + const json = await resp.json() as any; + if (json.error) return null; + + return { + access_token: json.access_token, + token_type: json.token_type, + expires_in: json.expires_in, + refresh_token: json.refresh_token, + scope: json.scope, + }; + }; + + static getUserDetails = async (token: string) => { + const resp = await fetch("https://discord.com/api/users/@me", { + headers: { + "Authorization": `Bearer ${token}`, + } + }); + + const json = await resp.json() as any; + if (!json.username || !json.email) return null; // eh, deal with bad code later + + return { + email: json.email, + username: json.username, + }; + }; +} + +const handlers: { [key: string]: any; } = { + "discord": Discord, +}; + +app.get("/oauth/:type", async (req, res) => { + const { type } = req.params; + if (!type) return res.sendStatus(400); + const handler = handlers[type]; + if (!handler) return res.sendStatus(400); + + const data = await handler.getAccessToken(req, res); + if (!data) return res.sendStatus(500); + + const details = await handler.getUserDetails(data.access_token); + if (!details) return res.sendStatus(500); + + let user = await User.findOne({ where: { email: details.email } }); + if (!user) { + user = await User.register({ + email: details.email, + username: details.username, + req + }); + } + + const token = await generateToken(user.id); + + res.cookie("token", token); + + res.sendFile(path.join(__dirname, "../public/login.html")); +}); + +app.get("*", (req, res) => { + res.sendFile(path.join(__dirname, "../public/login.html")); +}); + +(async () => { + await initDatabase(); + await Config.init(); + + app.listen(port, () => { + console.log(`Listening on port ${port}`); + }); +})(); \ No newline at end of file diff --git a/slowcord/tsconfig.json b/slowcord/tsconfig.json new file mode 100644 index 00000000..b8a5965d --- /dev/null +++ b/slowcord/tsconfig.json @@ -0,0 +1,99 @@ +{ + "exclude": [ + "node_modules" + ], + "include": [ + "src/**/*.ts" + ], + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + /* Projects */ + // "incremental": true, /* Enable incremental compilation */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + /* Language and Environment */ + "target": "ES6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "lib": ["ES2021"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ + // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + /* Modules */ + "module": "ES2020", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ + "types": ["node"], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "resolveJsonModule": true, /* Enable importing .json files */ + // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./build", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ + // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ + "strictPropertyInitialization": false, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} \ No newline at end of file diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts index f3c40c83..c2c6fbbc 100644 --- a/util/src/entities/Channel.ts +++ b/util/src/entities/Channel.ts @@ -245,6 +245,7 @@ export class Channel extends BaseClass { static async createDMChannel(recipients: string[], creator_user_id: string, name?: string) { recipients = recipients.unique().filter((x) => x !== creator_user_id); + //@ts-ignore some typeorm typescript issue const otherRecipientsUsers = await User.find({ where: recipients.map((x) => ({ id: x })) }); // TODO: check config for max number of recipients diff --git a/util/src/util/Event.ts b/util/src/util/Event.ts index bb624051..20a638a0 100644 --- a/util/src/util/Event.ts +++ b/util/src/util/Event.ts @@ -62,6 +62,7 @@ export async function listenEvent(event: string, callback: (event: EventOpts) => msg.type === "event" && msg.id === event && callback({ ...msg.event, cancel }); }; + //@ts-ignore apparently theres no function addListener with this signature process.addListener("message", listener); process.setMaxListeners(process.getMaxListeners() + 1);