feat(smartjwt): Add nested JWT functionality

This commit is contained in:
2024-09-05 16:46:01 +02:00
parent 59ae8ae466
commit 8097ca059f
6 changed files with 31 additions and 13 deletions

View File

@@ -87,7 +87,7 @@ export class SmartJwt<T extends object = any> {
public isObjectWithJwt<T extends object>(
public isNestedJwt<T extends object>(
object: unknown,
): object is IObjectWithJwt<T> {
return (
@@ -98,17 +98,22 @@ export class SmartJwt<T extends object = any> {
);
}
public jwtObjectGuard = new plugins.smartguard.Guard(async (dataArg: IObjectWithJwt<any>) => {
const jwtData = this.verifyJWTAndGetData(dataArg.jwt);
// check all other properties wether they match with jwtData
for (const key in dataArg) {
if (key !== 'jwt') {
if (jwtData[key] !== dataArg[key]) {
return false;
}
}
public async verifyNestedJwt<T extends object>(object: IObjectWithJwt<T>) {
const jwtData = await this.verifyJWTAndGetData(object.jwt);
(jwtData as any).jwt = object.jwt;
return plugins.smartjson.deepEqualObjects(object, jwtData);
}
public async createNestedJwt<T extends object>(payloadArg: T): Promise<IObjectWithJwt<T>> {
const jwt = await this.createJWT(payloadArg as any);
return {
...payloadArg,
jwt,
}
return true;
}
public nestedJwtGuard = new plugins.smartguard.Guard(async (dataArg: IObjectWithJwt<any>) => {
return this.verifyNestedJwt(dataArg);
}, {
name: 'jwtObjectGuard',
failedHint: 'is not a valid jwt object',