mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-09-30 06:12:26 -05:00
chore: remove magic numbers for token types
This commit is contained in:
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { getPNIDByUsername, getPNIDByTokenAuth } from '@/database';
|
||||
import { nintendoPasswordHash, generateToken } from '@/util';
|
||||
import { TokenType } from '@/types/common/token-types';
|
||||
import { config } from '@/config-manager';
|
||||
import { LOG_ERROR } from '@/logger';
|
||||
import type { HydratedPNIDDocument } from '@/types/mongoose/pnid';
|
||||
@@ -112,7 +113,7 @@ router.post('/', async (request: express.Request, response: express.Response): P
|
||||
|
||||
const accessTokenOptions = {
|
||||
system_type: 0x3, // * API
|
||||
token_type: 0x1, // * OAuth Access
|
||||
token_type: TokenType.OAuthAccess,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
@@ -121,7 +122,7 @@ router.post('/', async (request: express.Request, response: express.Response): P
|
||||
|
||||
const refreshTokenOptions = {
|
||||
system_type: 0x3, // * API
|
||||
token_type: 0x2, // * OAuth Refresh
|
||||
token_type: TokenType.OAuthRefresh,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
|
||||
@@ -7,6 +7,7 @@ import hcaptcha from 'hcaptcha';
|
||||
import Mii from 'mii-js';
|
||||
import { doesPNIDExist, connection as databaseConnection } from '@/database';
|
||||
import { nintendoPasswordHash, sendConfirmationEmail, generateToken } from '@/util';
|
||||
import { TokenType } from '@/types/common/token-types';
|
||||
import { LOG_ERROR } from '@/logger';
|
||||
import { PNID } from '@/models/pnid';
|
||||
import { NEXAccount } from '@/models/nex-account';
|
||||
@@ -369,7 +370,7 @@ router.post('/', async (request: express.Request, response: express.Response): P
|
||||
|
||||
const accessTokenOptions = {
|
||||
system_type: 0x3, // * API
|
||||
token_type: 0x1, // * OAuth Access
|
||||
token_type: TokenType.OAuthAccess,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
@@ -378,7 +379,7 @@ router.post('/', async (request: express.Request, response: express.Response): P
|
||||
|
||||
const refreshTokenOptions = {
|
||||
system_type: 0x3, // * API
|
||||
token_type: 0x2, // * OAuth Refresh
|
||||
token_type: TokenType.OAuthRefresh,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Status, ServerError } from 'nice-grpc';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { getPNIDByUsername, getPNIDByTokenAuth } from '@/database';
|
||||
import { nintendoPasswordHash, generateToken } from '@/util';
|
||||
import { TokenType } from '@/types/common/token-types';
|
||||
import { config } from '@/config-manager';
|
||||
import type { LoginRequest, LoginResponse, DeepPartial } from '@pretendonetwork/grpc/api/login_rpc';
|
||||
import type { HydratedPNIDDocument } from '@/types/mongoose/pnid';
|
||||
@@ -56,7 +57,7 @@ export async function login(request: LoginRequest): Promise<DeepPartial<LoginRes
|
||||
|
||||
const accessTokenOptions = {
|
||||
system_type: 0x3, // * API
|
||||
token_type: 0x1, // * OAuth Access
|
||||
token_type: TokenType.OAuthAccess,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
@@ -65,7 +66,7 @@ export async function login(request: LoginRequest): Promise<DeepPartial<LoginRes
|
||||
|
||||
const refreshTokenOptions = {
|
||||
system_type: 0x3, // * API
|
||||
token_type: 0x2, // * OAuth Refresh
|
||||
token_type: TokenType.OAuthRefresh,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
|
||||
@@ -10,6 +10,7 @@ import { nintendoPasswordHash, sendConfirmationEmail, generateToken } from '@/ut
|
||||
import { LOG_ERROR } from '@/logger';
|
||||
import { PNID } from '@/models/pnid';
|
||||
import { NEXAccount } from '@/models/nex-account';
|
||||
import { TokenType } from '@/types/common/token-types';
|
||||
import { config, disabledFeatures } from '@/config-manager';
|
||||
import type { LoginResponse } from '@pretendonetwork/grpc/api/login_rpc';
|
||||
import type { RegisterRequest, DeepPartial } from '@pretendonetwork/grpc/api/register_rpc';
|
||||
@@ -231,7 +232,7 @@ export async function register(request: RegisterRequest): Promise<DeepPartial<Lo
|
||||
|
||||
const accessTokenOptions = {
|
||||
system_type: 0x3, // * API
|
||||
token_type: 0x1, // * OAuth Access
|
||||
token_type: TokenType.OAuthAccess,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
@@ -240,7 +241,7 @@ export async function register(request: RegisterRequest): Promise<DeepPartial<Lo
|
||||
|
||||
const refreshTokenOptions = {
|
||||
system_type: 0x3, // * API
|
||||
token_type: 0x2, // * OAuth Refresh
|
||||
token_type: TokenType.OAuthRefresh,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
|
||||
@@ -3,6 +3,7 @@ import { nintendoBase64Encode, nintendoBase64Decode, nascDateTime, nascError, ge
|
||||
import { getServerByTitleID } from '@/database';
|
||||
import type { NASCRequestParams } from '@/types/services/nasc/request-params';
|
||||
import type { HydratedServerDocument } from '@/types/mongoose/server';
|
||||
import { TokenType } from '@/types/common/token-types';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -66,7 +67,7 @@ router.post('/', async (request: express.Request, response: express.Response): P
|
||||
async function processLoginRequest(server: HydratedServerDocument, pid: number, titleID: string): Promise<URLSearchParams> {
|
||||
const tokenOptions = {
|
||||
system_type: 0x2, // * 3DS
|
||||
token_type: 0x3, // * NEX token
|
||||
token_type: TokenType.NEX,
|
||||
pid: pid,
|
||||
access_level: 0,
|
||||
title_id: BigInt(parseInt(titleID, 16)),
|
||||
|
||||
@@ -5,6 +5,7 @@ import deviceCertificateMiddleware from '@/middleware/device-certificate';
|
||||
import consoleStatusVerificationMiddleware from '@/middleware/console-status-verification';
|
||||
import { getPNIDByTokenAuth, getPNIDByUsername } from '@/database';
|
||||
import { generateToken } from '@/util';
|
||||
import { TokenType } from '@/types/common/token-types';
|
||||
import { config } from '@/config-manager';
|
||||
import { Device } from '@/models/device';
|
||||
|
||||
@@ -153,14 +154,14 @@ router.post('/access_token/generate', deviceCertificateMiddleware, consoleStatus
|
||||
|
||||
const accessTokenOptions = {
|
||||
system_type: 0x1, // * WiiU
|
||||
token_type: 0x1, // * OAuth Access
|
||||
token_type: TokenType.OAuthAccess,
|
||||
pid: pnid.pid,
|
||||
expire_time: BigInt(Date.now() + (3600 * 1000))
|
||||
};
|
||||
|
||||
const refreshTokenOptions = {
|
||||
system_type: 0x1, // * WiiU
|
||||
token_type: 0x2, // * OAuth Refresh
|
||||
token_type: TokenType.OAuthRefresh,
|
||||
pid: pnid.pid,
|
||||
expire_time: BigInt(Date.now() + (3600 * 1000))
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import xmlbuilder from 'xmlbuilder';
|
||||
import { getServerByClientID, getServerByGameServerID } from '@/database';
|
||||
import { generateToken, getValueFromHeaders, getValueFromQueryString } from '@/util';
|
||||
import { TokenType } from '@/types/common/token-types';
|
||||
import { NEXAccount } from '@/models/nex-account';
|
||||
|
||||
const router = express.Router();
|
||||
@@ -91,7 +92,7 @@ router.get('/service_token/@me', async (request: express.Request, response: expr
|
||||
|
||||
const tokenOptions = {
|
||||
system_type: server.device,
|
||||
token_type: 0x4, // * Service token
|
||||
token_type: TokenType.IndependentService,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(parseInt(titleID, 16)),
|
||||
@@ -214,7 +215,7 @@ router.get('/nex_token/@me', async (request: express.Request, response: express.
|
||||
|
||||
const tokenOptions = {
|
||||
system_type: server.device,
|
||||
token_type: 0x3, // * nex token,
|
||||
token_type: TokenType.NEX,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(parseInt(titleID, 16)),
|
||||
@@ -239,4 +240,4 @@ router.get('/nex_token/@me', async (request: express.Request, response: express.
|
||||
}).end());
|
||||
});
|
||||
|
||||
export default router;
|
||||
export default router;
|
||||
|
||||
8
src/types/common/token-types.ts
Normal file
8
src/types/common/token-types.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// TODO - Maybe this shouldn't be in the `types` folder, since it's also actual data?
|
||||
export enum TokenType {
|
||||
OAuthAccess = 1,
|
||||
OAuthRefresh = 2,
|
||||
NEX = 3,
|
||||
IndependentService = 4,
|
||||
PasswordReset = 5
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import fs from 'fs-extra';
|
||||
import bufferCrc32 from 'buffer-crc32';
|
||||
import { crc32 } from 'crc';
|
||||
import { sendMail } from '@/mailer';
|
||||
import { TokenType } from '@/types/common/token-types';
|
||||
import { config, disabledFeatures } from '@/config-manager';
|
||||
import type { ParsedQs } from 'qs';
|
||||
import type mongoose from 'mongoose';
|
||||
@@ -240,7 +241,7 @@ export async function sendEmailConfirmedParentalControlsEmail(pnid: mongoose.Hyd
|
||||
export async function sendForgotPasswordEmail(pnid: mongoose.HydratedDocument<IPNID, IPNIDMethods>): Promise<void> {
|
||||
const tokenOptions = {
|
||||
system_type: 0xF, // * API
|
||||
token_type: 0x5, // * Password reset
|
||||
token_type: TokenType.PasswordReset,
|
||||
pid: pnid.pid,
|
||||
access_level: pnid.access_level,
|
||||
title_id: BigInt(0),
|
||||
|
||||
Reference in New Issue
Block a user