Skip to content

Commit 750b7f4

Browse files
committed
Fix Token Issuer
1 parent 0736ded commit 750b7f4

5 files changed

Lines changed: 16 additions & 23 deletions

File tree

src/components/license/LicenseForm.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ export function LicenseForm({ open, onOpenChange }: LicenseFormProps) {
9191
exp = Math.floor(expirationDate.getTime() / 1000);
9292
}
9393

94-
const license = await createLicense(activeRealm, {
95-
sub: client.trim(),
94+
const license = await createLicense(activeRealm, client.trim(), {
9695
label: label.trim() || undefined,
9796
kind: kind.trim() || undefined,
9897
flags: flags.trim()

src/components/license/LicenseList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export function LicenseList() {
4040
<div className="grid gap-4 sm:grid-cols-2">
4141
{licenses.map((license) => (
4242
<LicenseCard
43-
key={license.id}
43+
key={license.jti}
4444
license={license}
4545
onDelete={() =>
46-
deleteLicense(activeRealm.id, license.id)
46+
deleteLicense(activeRealm.id, license.jti)
4747
}
4848
/>
4949
))}

src/context/RealmContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function realmReducer(state: RealmState, action: RealmAction): RealmState {
131131
...realm,
132132
licenses: {
133133
...realm.licenses,
134-
[action.payload.license.id]:
134+
[action.payload.license.jti]:
135135
action.payload.license,
136136
},
137137
updatedAt: Date.now(),

src/lib/license.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as jose from "jose";
22
import type { License, Realm } from "@/lib/types";
33

4+
export const KEYWRIT_VERSION = 1;
5+
export const KEYWRIT_ISSUER = "keywrit";
6+
47
export interface LicenseParams {
5-
sub: string;
68
label?: string;
7-
iss?: string;
8-
aud?: string | string[];
99
kind?: string;
1010
flags?: string[];
1111
features?: Record<string, unknown>;
@@ -16,7 +16,8 @@ export interface LicenseParams {
1616

1717
export async function createLicense(
1818
realm: Realm,
19-
params: LicenseParams,
19+
sub: string,
20+
params: LicenseParams = {},
2021
): Promise<License> {
2122
const privateKey = await jose.importJWK(realm.keyPair.privateKey, "EdDSA");
2223

@@ -28,8 +29,6 @@ export async function createLicense(
2829
const jti = crypto.randomUUID();
2930

3031
// Merge realm defaults with provided params (params take precedence)
31-
const iss = params.iss ?? realm.defaults.iss;
32-
const aud = params.aud ?? realm.defaults.aud;
3332
const kind = params.kind ?? realm.defaults.kind;
3433
const flags = params.flags ?? realm.defaults.flags;
3534
const features = params.features ?? realm.defaults.features;
@@ -45,11 +44,10 @@ export async function createLicense(
4544
// Build JWT payload
4645
const payload: jose.JWTPayload = {
4746
jti,
48-
sub: params.sub,
47+
sub,
48+
iss: KEYWRIT_ISSUER,
49+
aud: realm.name,
4950
};
50-
51-
if (iss) payload.iss = iss;
52-
if (aud) payload.aud = aud;
5351
if (kind) payload.kind = kind;
5452
if (flags && flags.length > 0) payload.flags = flags;
5553
if (features && Object.keys(features).length > 0)
@@ -60,16 +58,15 @@ export async function createLicense(
6058
if (params.nbf) payload.nbf = params.nbf;
6159

6260
const token = await new jose.SignJWT(payload)
63-
.setProtectedHeader({ alg: "EdDSA" })
61+
.setProtectedHeader({ alg: "EdDSA", typ: "JWT", kwv: KEYWRIT_VERSION })
6462
.setIssuedAt(now)
6563
.sign(privateKey);
6664

6765
const license: License = {
68-
id: crypto.randomUUID(),
6966
jti,
70-
sub: params.sub,
71-
iss,
72-
aud,
67+
sub,
68+
iss: KEYWRIT_ISSUER,
69+
aud: realm.name,
7370
kind,
7471
flags,
7572
features,

src/lib/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export interface KeyPair {
88
}
99

1010
export interface RealmDefaults {
11-
iss?: string;
12-
aud?: string | string[];
1311
kind?: string;
1412
flags?: string[];
1513
features?: Record<string, unknown>;
@@ -18,7 +16,6 @@ export interface RealmDefaults {
1816
}
1917

2018
export interface License {
21-
id: string;
2219
jti: string;
2320
sub: string;
2421
iss?: string;

0 commit comments

Comments
 (0)