@opentdf/sdk 0.13.0-beta.119 → 0.13.0-beta.123

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.
Files changed (57) hide show
  1. package/README.md +60 -10
  2. package/dist/cjs/src/access/access-rpc.js +6 -5
  3. package/dist/cjs/src/access.js +18 -5
  4. package/dist/cjs/src/auth/interceptors.js +186 -0
  5. package/dist/cjs/src/auth/oidc.js +5 -3
  6. package/dist/cjs/src/index.js +6 -2
  7. package/dist/cjs/src/opentdf.js +40 -32
  8. package/dist/cjs/src/platform.js +3 -46
  9. package/dist/cjs/src/policy/api.js +9 -5
  10. package/dist/cjs/src/policy/discovery.js +10 -9
  11. package/dist/cjs/tdf3/src/client/index.js +35 -17
  12. package/dist/cjs/tdf3/src/tdf.js +8 -7
  13. package/dist/types/src/access/access-rpc.d.ts +3 -3
  14. package/dist/types/src/access/access-rpc.d.ts.map +1 -1
  15. package/dist/types/src/access.d.ts +3 -3
  16. package/dist/types/src/access.d.ts.map +1 -1
  17. package/dist/types/src/auth/interceptors.d.ts +99 -0
  18. package/dist/types/src/auth/interceptors.d.ts.map +1 -0
  19. package/dist/types/src/auth/oidc.d.ts +1 -1
  20. package/dist/types/src/auth/oidc.d.ts.map +1 -1
  21. package/dist/types/src/index.d.ts +1 -0
  22. package/dist/types/src/index.d.ts.map +1 -1
  23. package/dist/types/src/opentdf.d.ts +18 -15
  24. package/dist/types/src/opentdf.d.ts.map +1 -1
  25. package/dist/types/src/platform.d.ts +6 -3
  26. package/dist/types/src/platform.d.ts.map +1 -1
  27. package/dist/types/src/policy/api.d.ts +3 -3
  28. package/dist/types/src/policy/api.d.ts.map +1 -1
  29. package/dist/types/src/policy/discovery.d.ts +5 -5
  30. package/dist/types/src/policy/discovery.d.ts.map +1 -1
  31. package/dist/types/tdf3/src/client/index.d.ts +10 -1
  32. package/dist/types/tdf3/src/client/index.d.ts.map +1 -1
  33. package/dist/types/tdf3/src/tdf.d.ts +5 -2
  34. package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
  35. package/dist/web/src/access/access-rpc.js +6 -5
  36. package/dist/web/src/access.js +18 -5
  37. package/dist/web/src/auth/interceptors.js +142 -0
  38. package/dist/web/src/auth/oidc.js +5 -3
  39. package/dist/web/src/index.js +2 -1
  40. package/dist/web/src/opentdf.js +40 -32
  41. package/dist/web/src/platform.js +3 -46
  42. package/dist/web/src/policy/api.js +9 -5
  43. package/dist/web/src/policy/discovery.js +10 -9
  44. package/dist/web/tdf3/src/client/index.js +35 -17
  45. package/dist/web/tdf3/src/tdf.js +8 -7
  46. package/package.json +1 -1
  47. package/src/access/access-rpc.ts +5 -5
  48. package/src/access.ts +29 -13
  49. package/src/auth/interceptors.ts +197 -0
  50. package/src/auth/oidc.ts +5 -3
  51. package/src/index.ts +10 -0
  52. package/src/opentdf.ts +54 -34
  53. package/src/platform.ts +8 -52
  54. package/src/policy/api.ts +8 -5
  55. package/src/policy/discovery.ts +9 -9
  56. package/tdf3/src/client/index.ts +46 -17
  57. package/tdf3/src/tdf.ts +14 -11
@@ -19,6 +19,8 @@ import { OIDCRefreshTokenProvider } from '../../../src/auth/oidc-refreshtoken-pr
19
19
  import { OIDCExternalJwtProvider } from '../../../src/auth/oidc-externaljwt-provider.js';
20
20
  import { CryptoService } from '../crypto/declarations.js';
21
21
  import { type AuthProvider, HttpRequest, withHeaders } from '../../../src/auth/auth.js';
22
+ import { type AuthConfig } from '../../../src/auth/interceptors.js';
23
+ import { type Interceptor } from '@connectrpc/connect';
22
24
  import { getPlatformUrlFromKasEndpoint, rstrip, validateSecureUrl } from '../../../src/utils.js';
23
25
 
24
26
  import {
@@ -154,7 +156,10 @@ export interface ClientConfig {
154
156
  kasPublicKey?: string;
155
157
  oidcOrigin?: string;
156
158
  externalJwt?: string;
159
+ /** @deprecated since 0.14.0. Use `interceptors` instead. */
157
160
  authProvider?: AuthProvider;
161
+ /** Connect RPC interceptors for authentication. Preferred over authProvider. */
162
+ interceptors?: Interceptor[];
158
163
  readerUrl?: string;
159
164
  entityObjectEndpoint?: string;
160
165
  fileStreamServiceWorker?: string;
@@ -347,7 +352,11 @@ export class Client {
347
352
 
348
353
  readonly clientId?: string;
349
354
 
350
- readonly authProvider?: AuthProvider;
355
+ /**
356
+ * Resolved auth configuration. Set once in the constructor from either
357
+ * authProvider or interceptors. Threaded through all internal layers.
358
+ */
359
+ readonly auth?: AuthConfig;
351
360
 
352
361
  readonly readerUrl?: string;
353
362
 
@@ -424,13 +433,16 @@ export class Client {
424
433
  this.easEndpoint = clientConfig.easEndpoint;
425
434
  }
426
435
 
427
- this.authProvider = config.authProvider;
428
436
  this.clientConfig = clientConfig;
429
437
 
438
+ // Resolve auth once at the boundary. Internally, only `this.auth` is used.
439
+ let authProvider = config.authProvider;
430
440
  this.clientId = clientConfig.clientId;
431
- if (!this.authProvider) {
441
+ if (!authProvider && !config.interceptors?.length) {
432
442
  if (!clientConfig.clientId) {
433
- throw new ConfigurationError('Client ID or custom AuthProvider must be defined');
443
+ throw new ConfigurationError(
444
+ 'Client ID, custom AuthProvider, or interceptors must be defined'
445
+ );
434
446
  }
435
447
 
436
448
  //Are we exchanging a refreshToken for a bearer token (normal AuthCode browser auth flow)?
@@ -438,7 +450,7 @@ export class Client {
438
450
  //browser-based OIDC login and authentication process against the OIDC endpoint using their chosen method,
439
451
  //and provide us with a valid refresh token/clientId obtained from that process.
440
452
  if (clientConfig.refreshToken) {
441
- this.authProvider = new OIDCRefreshTokenProvider(
453
+ authProvider = new OIDCRefreshTokenProvider(
442
454
  {
443
455
  clientId: clientConfig.clientId,
444
456
  refreshToken: clientConfig.refreshToken,
@@ -448,7 +460,7 @@ export class Client {
448
460
  );
449
461
  } else if (clientConfig.externalJwt) {
450
462
  //Are we exchanging a JWT previously issued by a trusted external entity (e.g. Google) for a bearer token?
451
- this.authProvider = new OIDCExternalJwtProvider(
463
+ authProvider = new OIDCExternalJwtProvider(
452
464
  {
453
465
  clientId: clientConfig.clientId,
454
466
  externalJwt: clientConfig.externalJwt,
@@ -458,11 +470,25 @@ export class Client {
458
470
  );
459
471
  }
460
472
  }
461
- this.dpopKeys = createSessionKeys({
462
- authProvider: this.authProvider,
463
- cryptoService: this.cryptoService,
464
- dpopKeys: clientConfig.dpopKeys,
465
- });
473
+
474
+ // Resolve to AuthConfig: interceptors take precedence over authProvider.
475
+ if (config.interceptors?.length) {
476
+ this.auth = { interceptors: config.interceptors };
477
+ } else if (authProvider) {
478
+ this.auth = authProvider;
479
+ }
480
+
481
+ if (config.interceptors?.length && !authProvider) {
482
+ // Interceptor path: no updateClientPublicKey needed.
483
+ // Still need dpopKeys for request body signing (reqSignature).
484
+ this.dpopKeys = clientConfig.dpopKeys ?? this.cryptoService.generateSigningKeyPair();
485
+ } else {
486
+ this.dpopKeys = createSessionKeys({
487
+ authProvider,
488
+ cryptoService: this.cryptoService,
489
+ dpopKeys: clientConfig.dpopKeys,
490
+ });
491
+ }
466
492
  }
467
493
 
468
494
  /** Necessary only for testing. A dependency-injection approach should be preferred, but that is difficult currently */
@@ -566,9 +592,12 @@ export class Client {
566
592
  if (!this.platformUrl) {
567
593
  throw new ConfigurationError('platformUrl not set in TDF3 Client constructor');
568
594
  }
595
+ if (!this.auth) {
596
+ throw new ConfigurationError('AuthProvider or interceptors required for autoconfigure');
597
+ }
569
598
  const fetchedFQNValues = await attributeFQNsAsValues(
570
599
  this.platformUrl,
571
- this.authProvider as AuthProvider,
600
+ this.auth,
572
601
  ...fqnsWithoutValues
573
602
  );
574
603
  fetchedFQNValues.forEach((fetchedValue) => {
@@ -739,7 +768,7 @@ export class Client {
739
768
  contentStream: opts.source,
740
769
  mimeType,
741
770
  policy: policyObject,
742
- authProvider: this.authProvider,
771
+ auth: this.auth,
743
772
  progressHandler: this.clientConfig.progressHandler,
744
773
  keyForEncryption,
745
774
  keyForManifest,
@@ -775,14 +804,14 @@ export class Client {
775
804
  fulfillableObligationFQNs = [],
776
805
  }: DecryptParams): Promise<DecoratedReadableStream> {
777
806
  const dpopKeys = await this.dpopKeys;
778
- if (!this.authProvider) {
779
- throw new ConfigurationError('AuthProvider missing');
807
+ if (!this.auth) {
808
+ throw new ConfigurationError('AuthProvider or interceptors missing');
780
809
  }
781
810
  const chunker = await makeChunkable(source);
782
811
  if (!allowList && this.allowedKases) {
783
812
  allowList = this.allowedKases;
784
813
  } else if (this.platformUrl) {
785
- allowList = await fetchKeyAccessServers(this.platformUrl, this.authProvider);
814
+ allowList = await fetchKeyAccessServers(this.platformUrl, this.auth);
786
815
  } else {
787
816
  throw new ConfigurationError('platformUrl is required when allowedKases is empty');
788
817
  }
@@ -798,7 +827,7 @@ export class Client {
798
827
  return await (streamMiddleware as DecryptStreamMiddleware)(
799
828
  await readStream({
800
829
  allowList,
801
- authProvider: this.authProvider,
830
+ auth: this.auth,
802
831
  chunker,
803
832
  concurrencyLimit,
804
833
  cryptoService: this.cryptoService,
package/tdf3/src/tdf.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  UnsignedRewrapRequest_WithKeyAccessObjectSchema,
16
16
  } from '../../src/platform/kas/kas_pb.js';
17
17
  import { type AuthProvider, reqSignature } from '../../src/auth/auth.js';
18
+ import { type AuthConfig } from '../../src/auth/interceptors.js';
18
19
  import { handleRpcRewrapErrorString } from '../../src/access/access-rpc.js';
19
20
  import { allPool, anyPool } from '../../src/concurrency.js';
20
21
  import { base64, hex } from '../../src/encodings/index.js';
@@ -152,7 +153,8 @@ export type EncryptConfiguration = {
152
153
  contentStream: ReadableStream<Uint8Array>;
153
154
  mimeType?: string;
154
155
  policy: Policy;
155
- authProvider?: AuthProvider;
156
+ /** Auth configuration: AuthProvider or { interceptors }. */
157
+ auth?: AuthConfig;
156
158
  byteLimit: number;
157
159
  progressHandler?: (bytesProcessed: number) => void;
158
160
  keyForEncryption: KeyInfo;
@@ -166,7 +168,8 @@ export type DecryptConfiguration = {
166
168
  fulfillableObligations: string[];
167
169
  allowedKases?: string[];
168
170
  allowList?: OriginAllowList;
169
- authProvider: AuthProvider;
171
+ /** Auth configuration: AuthProvider or { interceptors }. */
172
+ auth?: AuthConfig;
170
173
  cryptoService: CryptoService;
171
174
 
172
175
  dpopKeys: KeyPair;
@@ -371,7 +374,7 @@ function isTargetSpecLegacyTDF(targetSpecVersion?: string): boolean {
371
374
  }
372
375
 
373
376
  export async function writeStream(cfg: EncryptConfiguration): Promise<DecoratedReadableStream> {
374
- if (!cfg.authProvider) {
377
+ if (!cfg.auth) {
375
378
  throw new ConfigurationError('No authorization middleware defined');
376
379
  }
377
380
  if (!cfg.contentStream) {
@@ -737,7 +740,7 @@ type RewrapResponseData = {
737
740
  async function unwrapKey({
738
741
  manifest,
739
742
  allowedKases,
740
- authProvider,
743
+ auth,
741
744
  dpopKeys,
742
745
  concurrencyLimit,
743
746
  cryptoService,
@@ -746,18 +749,18 @@ async function unwrapKey({
746
749
  }: {
747
750
  manifest: Manifest;
748
751
  allowedKases: OriginAllowList;
749
- authProvider: AuthProvider;
752
+ /** Auth configuration: AuthProvider or { interceptors }. */
753
+ auth?: AuthConfig;
750
754
  concurrencyLimit?: number;
751
755
  dpopKeys: KeyPair;
752
756
  cryptoService: CryptoService;
753
757
  wrappingKeyAlgorithm?: KasPublicKeyAlgorithm;
754
758
  fulfillableObligations: string[];
755
759
  }) {
756
- if (authProvider === undefined) {
757
- throw new ConfigurationError(
758
- 'rewrap requires auth provider; must be configured in client constructor'
759
- );
760
+ if (!auth) {
761
+ throw new ConfigurationError('rewrap requires auth; must be configured in client constructor');
760
762
  }
763
+ const resolvedAuth: AuthConfig = auth;
761
764
  const { keyAccess } = manifest.encryptionInformation;
762
765
  const splitPotentials = splitLookupTableFactory(keyAccess, allowedKases);
763
766
 
@@ -829,7 +832,7 @@ async function unwrapKey({
829
832
  const rewrapResp = await fetchWrappedKey(
830
833
  url,
831
834
  signedRequestToken,
832
- authProvider,
835
+ resolvedAuth,
833
836
  fulfillableObligations
834
837
  );
835
838
  // Upgrade V1 response to V2 format if needed
@@ -1143,7 +1146,7 @@ export async function decryptStreamFrom(
1143
1146
  const { metadata, reconstructedKey, requiredObligations } = await unwrapKey({
1144
1147
  fulfillableObligations: cfg.fulfillableObligations,
1145
1148
  manifest,
1146
- authProvider: cfg.authProvider,
1149
+ auth: cfg.auth,
1147
1150
  allowedKases: allowList,
1148
1151
  dpopKeys: cfg.dpopKeys,
1149
1152
  cryptoService: cfg.cryptoService,