mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-08-27 13:24:12 -05:00
fix: update remaining magic numbers for system/token types
This commit is contained in:
@@ -13,6 +13,7 @@ import type { PNIDProfile } from '@/types/services/nnas/pnid-profile';
|
||||
import type { ConnectionData } from '@/types/services/api/connection-data';
|
||||
import type { ConnectionResponse } from '@/types/services/api/connection-response';
|
||||
import type { DiscordConnectionData } from '@/types/services/api/discord-connection-data';
|
||||
import type { SystemType } from '@/types/common/system-types';
|
||||
|
||||
const connection_string = config.mongoose.connection_string;
|
||||
const options = config.mongoose.options;
|
||||
@@ -104,7 +105,7 @@ export async function getPNIDByBasicAuth(token: string): Promise<HydratedPNIDDoc
|
||||
return pnid;
|
||||
}
|
||||
|
||||
export async function getPNIDByTokenAuth(token: string, allowedTypes?: number[]): Promise<HydratedPNIDDocument | null> {
|
||||
export async function getPNIDByTokenAuth(token: string, allowedTypes?: SystemType[]): Promise<HydratedPNIDDocument | null> {
|
||||
verifyConnected();
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import { SystemType } from '@/types/common/system-types';
|
||||
import { getValueFromHeaders } from '@/util';
|
||||
import { getPNIDByBasicAuth, getPNIDByTokenAuth } from '@/database';
|
||||
import type express from 'express';
|
||||
@@ -24,7 +25,7 @@ async function PNIDMiddleware(request: express.Request, response: express.Respon
|
||||
pnid = await getPNIDByBasicAuth(token);
|
||||
} else if (type === 'Bearer') {
|
||||
// TODO - This "accepted types list" is mostly a hack. Change this
|
||||
pnid = await getPNIDByTokenAuth(token, [1, 2]);
|
||||
pnid = await getPNIDByTokenAuth(token, [SystemType.WUP, SystemType.CTR]);
|
||||
}
|
||||
|
||||
if (!pnid) {
|
||||
|
||||
@@ -64,7 +64,7 @@ export function generateToken(key: string, options: TokenOptions): Buffer | null
|
||||
dataBuffer.writeUInt32LE(options.pid, 0x2);
|
||||
dataBuffer.writeBigUInt64LE(options.expire_time, 0x6);
|
||||
|
||||
if ((options.token_type !== 0x1 && options.token_type !== 0x2) || options.system_type === 0x3) {
|
||||
if ((options.token_type !== TokenType.OAuthAccess && options.token_type !== TokenType.OAuthRefresh) || options.system_type === SystemType.API) {
|
||||
// * Access and refresh tokens have smaller bodies due to size constraints
|
||||
// * The API does not have this restraint, however
|
||||
if (options.title_id === undefined || options.access_level === undefined) {
|
||||
@@ -90,7 +90,7 @@ export function generateToken(key: string, options: TokenOptions): Buffer | null
|
||||
|
||||
let final = encrypted;
|
||||
|
||||
if ((options.token_type !== 0x1 && options.token_type !== 0x2) || options.system_type === 0x3) {
|
||||
if ((options.token_type !== TokenType.OAuthAccess && options.token_type !== TokenType.OAuthRefresh) || options.system_type === SystemType.API) {
|
||||
// * Access and refresh tokens don't get a checksum due to size constraints
|
||||
const checksum = bufferCrc32(dataBuffer);
|
||||
|
||||
@@ -142,7 +142,7 @@ export function unpackToken(token: Buffer): Token {
|
||||
expire_time: token.readBigUInt64LE(0x6)
|
||||
};
|
||||
|
||||
if (unpacked.token_type !== 0x1 && unpacked.token_type !== 0x2) {
|
||||
if (unpacked.token_type !== TokenType.OAuthAccess && unpacked.token_type !== TokenType.OAuthRefresh) {
|
||||
unpacked.title_id = token.readBigUInt64LE(0xE);
|
||||
unpacked.access_level = token.readInt8(0x16);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user