mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-04-26 00:06:14 -05:00
fix: make NNAS middleware only accept console tokens
This commit is contained in:
parent
1653b09988
commit
8e557fc072
|
|
@ -104,12 +104,17 @@ export async function getPNIDByBasicAuth(token: string): Promise<HydratedPNIDDoc
|
||||||
return pnid;
|
return pnid;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPNIDByTokenAuth(token: string): Promise<HydratedPNIDDocument | null> {
|
export async function getPNIDByTokenAuth(token: string, allowedTypes?: number[]): Promise<HydratedPNIDDocument | null> {
|
||||||
verifyConnected();
|
verifyConnected();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const decryptedToken = decryptToken(Buffer.from(token, 'hex'));
|
const decryptedToken = decryptToken(Buffer.from(token, 'hex'));
|
||||||
const unpackedToken = unpackToken(decryptedToken);
|
const unpackedToken = unpackToken(decryptedToken);
|
||||||
|
|
||||||
|
if (allowedTypes && !allowedTypes.includes(unpackedToken.system_type)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const pnid = await getPNIDByPID(unpackedToken.pid);
|
const pnid = await getPNIDByPID(unpackedToken.pid);
|
||||||
|
|
||||||
if (pnid) {
|
if (pnid) {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ async function PNIDMiddleware(request: express.Request, response: express.Respon
|
||||||
const parts = authHeader.split(' ');
|
const parts = authHeader.split(' ');
|
||||||
const type = parts[0];
|
const type = parts[0];
|
||||||
let token = parts[1];
|
let token = parts[1];
|
||||||
let pnid: HydratedPNIDDocument | null;
|
let pnid: HydratedPNIDDocument | null = null;
|
||||||
|
|
||||||
if (request.isCemu) {
|
if (request.isCemu) {
|
||||||
token = Buffer.from(token, 'hex').toString('base64');
|
token = Buffer.from(token, 'hex').toString('base64');
|
||||||
|
|
@ -22,8 +22,9 @@ async function PNIDMiddleware(request: express.Request, response: express.Respon
|
||||||
|
|
||||||
if (type === 'Basic') {
|
if (type === 'Basic') {
|
||||||
pnid = await getPNIDByBasicAuth(token);
|
pnid = await getPNIDByBasicAuth(token);
|
||||||
} else {
|
} else if (type === 'Bearer') {
|
||||||
pnid = await getPNIDByTokenAuth(token);
|
// TODO - This "accepted types list" is mostly a hack. Change this
|
||||||
|
pnid = await getPNIDByTokenAuth(token, [1, 2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pnid) {
|
if (!pnid) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user