forked from zombieb/galvanic-corrosion-rewrite
duhhhhhhhh
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import z from "zod";
|
||||
import Command from "../commands/command.ts";
|
||||
import { ServerContentBase } from "../ContentBase.ts";
|
||||
import { transformCheckEnum, transformStringToEnum } from "../../util/validators.ts";
|
||||
import { transformCheckEnum } from "../../util/validators.ts";
|
||||
import { sign } from "@hono/hono/jwt";
|
||||
import { CachedLogin, DbCachedLogin, PlatformMask, PlatformType, TokenFormat, TokenType } from "./types.ts";
|
||||
import type Profile from "../profiles/profile.ts";
|
||||
import { getNetConfig } from "../../net.ts";
|
||||
|
||||
export const steamAuthTicketSchema = z.object({
|
||||
Ticket: z.string().min(256),
|
||||
AppId: z.literal("471710")
|
||||
});
|
||||
|
||||
const netConfig = getNetConfig();
|
||||
|
||||
export class PlatformsManager extends ServerContentBase {
|
||||
|
||||
static platformsKey = "platforms";
|
||||
@@ -18,15 +22,18 @@ export class PlatformsManager extends ServerContentBase {
|
||||
return [PlatformsManager.platformsKey, ...keys.filter(val => typeof val == 'string')];
|
||||
}
|
||||
|
||||
async getToken(accountId: number, type: TokenType) {
|
||||
async getToken(prof: Profile, type: TokenType) {
|
||||
const secret = Deno.env.get('SECRET');
|
||||
if (!secret) throw new Error("No SECRET in env. Did you forget to set it?");
|
||||
|
||||
const exp = type == TokenType.Access ? Math.round(Date.now() / 1000) + 21_600 : Math.round(Date.now() / 1000) + 31_556_952;
|
||||
|
||||
const token: TokenFormat = {
|
||||
typ: type,
|
||||
sub: accountId,
|
||||
iss: "https://yarns.proxnet.dev/auth/",
|
||||
exp: type == TokenType.Access ? Math.round(Date.now() / 1000) + 21_600 : Math.round(Date.now() / 1000) + 31_556_952
|
||||
sub: prof.getId(),
|
||||
role: await prof.getRole(),
|
||||
iss: `${netConfig.securePublicHost ? "https" : "http"}://${netConfig.publicHost}/auth`,
|
||||
iat: Math.round(Date.now() / 1000) - 5,
|
||||
exp
|
||||
}
|
||||
return await sign(JSON.parse(JSON.stringify(token)), secret);
|
||||
}
|
||||
@@ -138,9 +145,9 @@ export class PlatformsManager extends ServerContentBase {
|
||||
return await this.addCachedLogin(type, platformId, accountId);
|
||||
},
|
||||
zod: z.tuple([
|
||||
z.string().transform(transformStringToEnum<PlatformType>(PlatformType)),
|
||||
z.coerce.number().transform(transformCheckEnum<PlatformType>(PlatformType)),
|
||||
z.string(),
|
||||
z.string().transform(Number)
|
||||
z.coerce.number()
|
||||
]),
|
||||
help: 'Add a cachedlogin for platformId: <type: PlatformType>, <platformId: string>, <accountId: number>'
|
||||
}),
|
||||
@@ -150,9 +157,9 @@ export class PlatformsManager extends ServerContentBase {
|
||||
return await this.deleteCachedLogin(type, platformId, accountId);
|
||||
},
|
||||
zod: z.tuple([
|
||||
z.string().transform(transformStringToEnum<PlatformType>(PlatformType)),
|
||||
z.coerce.number().transform(transformCheckEnum<PlatformType>(PlatformType)),
|
||||
z.string(),
|
||||
z.string().transform(Number)
|
||||
z.coerce.number()
|
||||
]),
|
||||
help: 'Remove a cachedlogin for platformId: <type: PlatformType>, <platformId: string>, <accountId: number>'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user