Skip to content

Commit

Permalink
WIP: quick save changes
Browse files Browse the repository at this point in the history
  • Loading branch information
schettn committed Sep 28, 2023
1 parent 457acb0 commit 7d4654a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added client/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@snek-functions/jwt",
"type": "module",
"version": "0.0.37",
"version": "0.0.38",
"description": "Auto-generated API client",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion client/src/schema.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class UserTokenPayload {
type: t.Nullable<ACCESS_REFRESH>;
sub: t.String;
scope: t.NotSupportedYet;
roles: t.Nullable<t.String>[];
roles: t.String[];
iat: t.Nullable<t.Number>;
exp: t.Nullable<t.Number>;
jti: t.String;
Expand Down
22 changes: 20 additions & 2 deletions src/utils/TokenFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface UserTokenPayload {
type: "access" | "refresh";
sub: string;
scope: { [key: string]: string[] };
roles?: string[];
roles: string[];
iat?: number;
exp?: number;
jti: string;
Expand Down Expand Up @@ -114,7 +114,13 @@ export class TokenFactory {
}

private checkUserTokenPayload(payload: UserTokenPayload): void {
if (!payload.scope || !payload.sub || !payload.aud || !payload.jti) {
if (
!payload.scope ||
!payload.sub ||
!payload.aud ||
!payload.jti ||
!payload.roles
) {
throw new InvalidTokenError();
}
}
Expand All @@ -136,6 +142,12 @@ export class TokenFactory {
if (payload.resourceId) {
payload.aud = payload.resourceId;
}
if (!payload.roles) {
payload.roles = [];
}
if (!payload.scope) {
payload.scope = {};
}

this.checkUserTokenPayload(payload);

Expand All @@ -155,6 +167,12 @@ export class TokenFactory {
if (payload.resourceId) {
payload.aud = payload.resourceId;
}
if (!payload.roles) {
payload.roles = [];
}
if (!payload.scope) {
payload.scope = {};
}

this.checkUserTokenPayload(payload);

Expand Down

0 comments on commit 7d4654a

Please sign in to comment.