@saurbit/oauth2-jwt 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/esm/jose_jwks_authority.js +3 -3
- package/package.json +2 -2
- package/script/jose_jwks_authority.js +3 -3
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ JWT utilities and JWKS authority for [`@saurbit/oauth2`](https://jsr.io/@saurbit
|
|
|
4
4
|
[jose](https://github.com/panva/jose) to provide ready-made implementations of the JWT-related
|
|
5
5
|
interfaces required by `@saurbit/oauth2`.
|
|
6
6
|
|
|
7
|
+
📖 [Documentation](https://saurbit.github.io/website/packages/oauth2-jwt/)
|
|
8
|
+
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
9
11
|
**Node.js / Bun**
|
|
@@ -124,7 +124,7 @@ export class JoseJwksAuthority {
|
|
|
124
124
|
}
|
|
125
125
|
const privateKey = await importJWK(key, "RS256");
|
|
126
126
|
const token = await new SignJWT(payload)
|
|
127
|
-
.setProtectedHeader({ typ: "
|
|
127
|
+
.setProtectedHeader({ typ: "JWT", alg: "RS256", kid: key.kid })
|
|
128
128
|
.sign(privateKey);
|
|
129
129
|
return { token, kid: key.kid };
|
|
130
130
|
}
|
|
@@ -154,7 +154,7 @@ export class JoseJwksAuthority {
|
|
|
154
154
|
if ("jwk" in protectedHeader) {
|
|
155
155
|
throw new Error("Unexpected JWK in header - potential forgery attempt");
|
|
156
156
|
}
|
|
157
|
-
if (protectedHeader.typ && protectedHeader.typ.
|
|
157
|
+
if (protectedHeader.typ && protectedHeader.typ.toUpperCase() !== "JWT") {
|
|
158
158
|
throw new Error(`Unexpected typ: ${protectedHeader.typ}`);
|
|
159
159
|
}
|
|
160
160
|
return payload;
|
|
@@ -178,7 +178,7 @@ export class JoseJwksAuthority {
|
|
|
178
178
|
const result = [];
|
|
179
179
|
for (const payload of payloads) {
|
|
180
180
|
const token = await new SignJWT(payload)
|
|
181
|
-
.setProtectedHeader({ typ: "
|
|
181
|
+
.setProtectedHeader({ typ: "JWT", alg: "RS256", kid: key.kid })
|
|
182
182
|
.sign(privateKey);
|
|
183
183
|
result.push({ token, kid: key.kid });
|
|
184
184
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saurbit/oauth2-jwt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "JWT utilities for @saurbit/oauth2 (jose-based)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"oauth2",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"jose": "^6.2.2"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@saurbit/oauth2": "^0.1.
|
|
30
|
+
"@saurbit/oauth2": "^0.1.1"
|
|
31
31
|
},
|
|
32
32
|
"_generatedBy": "dnt@dev"
|
|
33
33
|
}
|
|
@@ -127,7 +127,7 @@ class JoseJwksAuthority {
|
|
|
127
127
|
}
|
|
128
128
|
const privateKey = await (0, jose_1.importJWK)(key, "RS256");
|
|
129
129
|
const token = await new jose_1.SignJWT(payload)
|
|
130
|
-
.setProtectedHeader({ typ: "
|
|
130
|
+
.setProtectedHeader({ typ: "JWT", alg: "RS256", kid: key.kid })
|
|
131
131
|
.sign(privateKey);
|
|
132
132
|
return { token, kid: key.kid };
|
|
133
133
|
}
|
|
@@ -157,7 +157,7 @@ class JoseJwksAuthority {
|
|
|
157
157
|
if ("jwk" in protectedHeader) {
|
|
158
158
|
throw new Error("Unexpected JWK in header - potential forgery attempt");
|
|
159
159
|
}
|
|
160
|
-
if (protectedHeader.typ && protectedHeader.typ.
|
|
160
|
+
if (protectedHeader.typ && protectedHeader.typ.toUpperCase() !== "JWT") {
|
|
161
161
|
throw new Error(`Unexpected typ: ${protectedHeader.typ}`);
|
|
162
162
|
}
|
|
163
163
|
return payload;
|
|
@@ -181,7 +181,7 @@ class JoseJwksAuthority {
|
|
|
181
181
|
const result = [];
|
|
182
182
|
for (const payload of payloads) {
|
|
183
183
|
const token = await new jose_1.SignJWT(payload)
|
|
184
|
-
.setProtectedHeader({ typ: "
|
|
184
|
+
.setProtectedHeader({ typ: "JWT", alg: "RS256", kid: key.kid })
|
|
185
185
|
.sign(privateKey);
|
|
186
186
|
result.push({ token, kid: key.kid });
|
|
187
187
|
}
|