@sparkvault/sdk-js 6.0.0 → 7.0.0
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/dist/index.d.ts +15 -7
- package/dist/products/identity/index.d.ts +15 -7
- package/dist/sparkvault.cjs.js +34 -9
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +34 -9
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -342,18 +342,26 @@ declare class IdentityModule {
|
|
|
342
342
|
*/
|
|
343
343
|
attach(selector: string, options?: AttachOptions): () => void;
|
|
344
344
|
/**
|
|
345
|
-
*
|
|
346
|
-
* Validates the token structure, expiry, and issuer.
|
|
345
|
+
* Decode an identity token's claims WITHOUT verifying its signature.
|
|
347
346
|
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
347
|
+
* This is an UNVERIFIED, client-side decode: it parses the JWT payload and
|
|
348
|
+
* sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
|
|
349
|
+
* `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
|
|
350
|
+
* cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
|
|
351
|
+
* result MUST NOT be trusted for any authorization decision.
|
|
352
|
+
*
|
|
353
|
+
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
354
|
+
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
355
|
+
* (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
350
356
|
*/
|
|
351
|
-
|
|
357
|
+
decodeToken(token: string): TokenClaims;
|
|
352
358
|
/**
|
|
353
359
|
* Complete full-page redirect results produced by social-login flows.
|
|
354
360
|
* The Identity Product redirects back with `#token=...` so the token does
|
|
355
|
-
* not hit server logs. Consume it once,
|
|
356
|
-
*
|
|
361
|
+
* not hit server logs. Consume it once, run the unverified client-side decode
|
|
362
|
+
* (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
|
|
363
|
+
* remove it from the URL bar. The host must still verify the token server-side
|
|
364
|
+
* via the Identity JWKS before trusting any claim.
|
|
357
365
|
*/
|
|
358
366
|
private consumeRedirectResult;
|
|
359
367
|
/**
|
|
@@ -72,18 +72,26 @@ export declare class IdentityModule {
|
|
|
72
72
|
*/
|
|
73
73
|
attach(selector: string, options?: AttachOptions): () => void;
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
76
|
-
* Validates the token structure, expiry, and issuer.
|
|
75
|
+
* Decode an identity token's claims WITHOUT verifying its signature.
|
|
77
76
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
77
|
+
* This is an UNVERIFIED, client-side decode: it parses the JWT payload and
|
|
78
|
+
* sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
|
|
79
|
+
* `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
|
|
80
|
+
* cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
|
|
81
|
+
* result MUST NOT be trusted for any authorization decision.
|
|
82
|
+
*
|
|
83
|
+
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
84
|
+
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
85
|
+
* (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
80
86
|
*/
|
|
81
|
-
|
|
87
|
+
decodeToken(token: string): TokenClaims;
|
|
82
88
|
/**
|
|
83
89
|
* Complete full-page redirect results produced by social-login flows.
|
|
84
90
|
* The Identity Product redirects back with `#token=...` so the token does
|
|
85
|
-
* not hit server logs. Consume it once,
|
|
86
|
-
*
|
|
91
|
+
* not hit server logs. Consume it once, run the unverified client-side decode
|
|
92
|
+
* (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
|
|
93
|
+
* remove it from the URL bar. The host must still verify the token server-side
|
|
94
|
+
* via the Identity JWKS before trusting any claim.
|
|
87
95
|
*/
|
|
88
96
|
private consumeRedirectResult;
|
|
89
97
|
/**
|
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -7934,13 +7934,19 @@ class IdentityModule {
|
|
|
7934
7934
|
return cleanup;
|
|
7935
7935
|
}
|
|
7936
7936
|
/**
|
|
7937
|
-
*
|
|
7938
|
-
* Validates the token structure, expiry, and issuer.
|
|
7937
|
+
* Decode an identity token's claims WITHOUT verifying its signature.
|
|
7939
7938
|
*
|
|
7940
|
-
*
|
|
7941
|
-
*
|
|
7939
|
+
* This is an UNVERIFIED, client-side decode: it parses the JWT payload and
|
|
7940
|
+
* sanity-checks structure, `exp`, `iss`, `aud`, and the header `alg` (rejecting
|
|
7941
|
+
* `none` and any non-EdDSA algorithm so an unsigned or algorithm-confused token
|
|
7942
|
+
* cannot masquerade as valid). It does NOT verify the Ed25519 signature, so its
|
|
7943
|
+
* result MUST NOT be trusted for any authorization decision.
|
|
7944
|
+
*
|
|
7945
|
+
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
7946
|
+
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
7947
|
+
* (`/v1/products/identity/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
7942
7948
|
*/
|
|
7943
|
-
|
|
7949
|
+
decodeToken(token) {
|
|
7944
7950
|
if (!token || typeof token !== 'string') {
|
|
7945
7951
|
throw new ValidationError('Token is required');
|
|
7946
7952
|
}
|
|
@@ -7948,7 +7954,17 @@ class IdentityModule {
|
|
|
7948
7954
|
if (parts.length !== 3) {
|
|
7949
7955
|
throw new ValidationError('Invalid token format');
|
|
7950
7956
|
}
|
|
7951
|
-
const [, payloadB64] = parts;
|
|
7957
|
+
const [headerB64, payloadB64] = parts;
|
|
7958
|
+
const header = JSON.parse(base64urlToString(headerB64));
|
|
7959
|
+
if (typeof header !== 'object' || header === null) {
|
|
7960
|
+
throw new ValidationError('Invalid token header');
|
|
7961
|
+
}
|
|
7962
|
+
// Reject alg:none (unsigned) and any algorithm other than EdDSA. Identity
|
|
7963
|
+
// tokens are Ed25519-signed; anything else is an unsigned or algorithm-
|
|
7964
|
+
// confused token that could never pass server-side JWKS verification.
|
|
7965
|
+
if (header.alg !== 'EdDSA') {
|
|
7966
|
+
throw new ValidationError('Unsupported token algorithm');
|
|
7967
|
+
}
|
|
7952
7968
|
const payload = JSON.parse(base64urlToString(payloadB64));
|
|
7953
7969
|
if (!isTokenClaims(payload)) {
|
|
7954
7970
|
throw new ValidationError('Invalid token payload structure');
|
|
@@ -7961,13 +7977,18 @@ class IdentityModule {
|
|
|
7961
7977
|
if (payload.iss !== expectedIssuer) {
|
|
7962
7978
|
throw new ValidationError('Invalid token issuer');
|
|
7963
7979
|
}
|
|
7980
|
+
if (payload.aud !== this.config.accountId) {
|
|
7981
|
+
throw new ValidationError('Invalid token audience');
|
|
7982
|
+
}
|
|
7964
7983
|
return payload;
|
|
7965
7984
|
}
|
|
7966
7985
|
/**
|
|
7967
7986
|
* Complete full-page redirect results produced by social-login flows.
|
|
7968
7987
|
* The Identity Product redirects back with `#token=...` so the token does
|
|
7969
|
-
* not hit server logs. Consume it once,
|
|
7970
|
-
*
|
|
7988
|
+
* not hit server logs. Consume it once, run the unverified client-side decode
|
|
7989
|
+
* (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
|
|
7990
|
+
* remove it from the URL bar. The host must still verify the token server-side
|
|
7991
|
+
* via the Identity JWKS before trusting any claim.
|
|
7971
7992
|
*/
|
|
7972
7993
|
async consumeRedirectResult() {
|
|
7973
7994
|
if (typeof window === 'undefined' || !window.location.hash) {
|
|
@@ -7994,7 +8015,11 @@ class IdentityModule {
|
|
|
7994
8015
|
if (expectedState && params.get('state') !== expectedState) {
|
|
7995
8016
|
throw new ValidationError('Invalid OAuth state');
|
|
7996
8017
|
}
|
|
7997
|
-
|
|
8018
|
+
// Unverified client-side decode — surfaces the claims for the result
|
|
8019
|
+
// shape and rejects an obviously-bad token (expiry/issuer/audience/alg).
|
|
8020
|
+
// The host MUST still verify result.token server-side via the Identity
|
|
8021
|
+
// JWKS before trusting any claim for an authorization decision.
|
|
8022
|
+
const claims = this.decodeToken(token);
|
|
7998
8023
|
return {
|
|
7999
8024
|
token,
|
|
8000
8025
|
identity: claims.identity,
|