@atol-sh/js 0.4.0 → 0.4.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/dist/index.d.cts CHANGED
@@ -496,12 +496,13 @@ interface AtolBrowserAuth {
496
496
  */
497
497
  completeLogin(): Promise<AtolSession>;
498
498
  /**
499
- * Mint a new credential pair scoped to `organizationId`. This is a
499
+ * Mint a new credential pair scoped to `organizationId`. Pass `null` to
500
+ * require an unscoped credential pair for the same authenticated user. This is a
500
501
  * distinct prompt=none authorization transaction, never an alias for a
501
502
  * generic renewal. The previous credential pair remains active if the
502
503
  * selection fails.
503
504
  */
504
- selectOrganization(organizationId: string): Promise<AtolSession>;
505
+ selectOrganization(organizationId: string | null): Promise<AtolSession>;
505
506
  /**
506
507
  * Return the current access token, renewing it when it is inside the 60s
507
508
  * expiry window. With `opts.dpop` and DPoP active, also returns a bound
@@ -537,10 +538,10 @@ interface AtolBrowserAuth {
537
538
  */
538
539
  getEncryptionError(): Error | undefined;
539
540
  /**
540
- * Cancel the response-vault interactive login owned by the current browser
541
- * generation without ending an established session or navigating to the
542
- * issuer. Resolves only after exact server rejection and local custody
543
- * release. Unsupported auth modes and initialized/session states reject.
541
+ * Cancel the pending login owned by the current browser generation without
542
+ * ending an established session or navigating to the issuer. Resolves after
543
+ * local custody is released and any submitted authorization is rejected by
544
+ * the server. Use an uninitialized client without an established session.
544
545
  */
545
546
  cancelLogin(): Promise<void>;
546
547
  /**
@@ -621,6 +622,61 @@ interface CredentialGenerationSnapshot {
621
622
 
622
623
  declare const RESPONSE_VAULT_PROTOCOL_VERSION: 1;
623
624
 
625
+ /** Parsed, state-validated redirect result before the token exchange. */
626
+ interface AuthorizationCodeCallback {
627
+ code: string;
628
+ codeVerifier: string;
629
+ redirectUri: string;
630
+ nonce: string;
631
+ returnTo?: string;
632
+ credentialGeneration?: CredentialGenerationSnapshot;
633
+ }
634
+ /**
635
+ * Create an oidc-client-ts UserManager configured for Atol.
636
+ *
637
+ * Storage policy:
638
+ * - `userStore` is IN-MEMORY. The full User object (access token, ID
639
+ * token, and -- when `useRefreshTokens` is on -- the refresh token)
640
+ * never touches sessionStorage or localStorage, so an XSS payload
641
+ * cannot read persisted credentials after the fact. The cost is that
642
+ * a page reload starts with an empty store; the provider recovers by
643
+ * attempting a silent renew against the IdP session cookie.
644
+ * - `stateStore` stays in sessionStorage. It only holds the OIDC
645
+ * state/PKCE verifier, which must survive the same-tab redirect to
646
+ * the Atol login page and back, and is worthless to an attacker
647
+ * after the code exchange completes.
648
+ */
649
+ declare function createUserManager(authority: string, clientId: string, redirectUri: string, scope: string, audience?: string): UserManager;
650
+ /**
651
+ * Read a redirect callback without letting oidc-client-ts exchange the code.
652
+ * The matching state remains present until the caller definitively settles
653
+ * its code exchange.
654
+ */
655
+ declare function readAuthorizationCodeCallback(manager: UserManager, url: string): Promise<AuthorizationCodeCallback>;
656
+ /** Extract the access token from an oidc-client-ts User. */
657
+ declare function getAccessToken(user: User | null): string | undefined;
658
+ /** Extract the ID token from an oidc-client-ts User. */
659
+ declare function getIdToken(user: User | null): string | undefined;
660
+ /**
661
+ * Build an oidc-client-ts User from a raw /auth/token response. Used to
662
+ * write renewed tokens back into the UserManager store so `mgr.getUser()`
663
+ * and React state never disagree (e.g. a rotated-away refresh token
664
+ * lingering in the store).
665
+ *
666
+ * `expires_at` prefers the access token's own `exp` claim; falls back to
667
+ * `expires_in` relative to now when the token is opaque.
668
+ */
669
+ declare function userFromTokenResponse(tokens: TokenResponse): User;
670
+
671
+ declare class OrdinaryAuthorizationPendingError extends Error {
672
+ constructor();
673
+ }
674
+ /** An existing browser authorization must settle before its intent can change. */
675
+ declare class OrdinaryAuthorizationIntentConflictError extends Error {
676
+ readonly pendingMode: 'silent' | 'interactive';
677
+ constructor(pendingMode: 'silent' | 'interactive');
678
+ }
679
+
624
680
  /**
625
681
  * Parse Atol custom claims from a JWT token (ID token or access token).
626
682
  * Decodes the payload without verifying the signature — verification is
@@ -674,52 +730,6 @@ declare function verifyAccessToken(accessToken: string, opts: {
674
730
  /** Test-only: drop the discovery cache so a test can re-stub the IdP. */
675
731
  declare function _resetDiscoveryCache(): void;
676
732
 
677
- /** Parsed, state-validated redirect result before the token exchange. */
678
- interface AuthorizationCodeCallback {
679
- code: string;
680
- codeVerifier: string;
681
- redirectUri: string;
682
- nonce: string;
683
- returnTo?: string;
684
- credentialGeneration?: CredentialGenerationSnapshot;
685
- }
686
- /**
687
- * Create an oidc-client-ts UserManager configured for Atol.
688
- *
689
- * Storage policy:
690
- * - `userStore` is IN-MEMORY. The full User object (access token, ID
691
- * token, and -- when `useRefreshTokens` is on -- the refresh token)
692
- * never touches sessionStorage or localStorage, so an XSS payload
693
- * cannot read persisted credentials after the fact. The cost is that
694
- * a page reload starts with an empty store; the provider recovers by
695
- * attempting a silent renew against the IdP session cookie.
696
- * - `stateStore` stays in sessionStorage. It only holds the OIDC
697
- * state/PKCE verifier, which must survive the same-tab redirect to
698
- * the Atol login page and back, and is worthless to an attacker
699
- * after the code exchange completes.
700
- */
701
- declare function createUserManager(authority: string, clientId: string, redirectUri: string, scope: string, audience?: string): UserManager;
702
- /**
703
- * Read a redirect callback without letting oidc-client-ts exchange the code.
704
- * The matching state remains present until the caller definitively settles
705
- * its code exchange.
706
- */
707
- declare function readAuthorizationCodeCallback(manager: UserManager, url: string): Promise<AuthorizationCodeCallback>;
708
- /** Extract the access token from an oidc-client-ts User. */
709
- declare function getAccessToken(user: User | null): string | undefined;
710
- /** Extract the ID token from an oidc-client-ts User. */
711
- declare function getIdToken(user: User | null): string | undefined;
712
- /**
713
- * Build an oidc-client-ts User from a raw /auth/token response. Used to
714
- * write renewed tokens back into the UserManager store so `mgr.getUser()`
715
- * and React state never disagree (e.g. a rotated-away refresh token
716
- * lingering in the store).
717
- *
718
- * `expires_at` prefers the access token's own `exp` claim; falls back to
719
- * `expires_in` relative to now when the token is opaque.
720
- */
721
- declare function userFromTokenResponse(tokens: TokenResponse): User;
722
-
723
733
  /**
724
734
  * Cross-tab mutual exclusion for renewal work.
725
735
  *
@@ -940,4 +950,4 @@ declare function stringToBase64Url(input: string): string;
940
950
  */
941
951
  declare function base64ToBytes(b64: string): Uint8Array;
942
952
 
943
- export { type AtolBrowserAuth, AtolBrowserAuthCleanupError, type AtolBrowserAuthConfig, type AtolSession, type AtolUser, type AuthorizationCodeCallback, AuthorizationCodeExchangeUncertainError, type BeginLoginOptions, type BroadcastMessage, type CredentialsInvalidatedMessage, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, type DPoPConfig, type DPoPKeyManager, type DPoPProofOptions, type DPoPProofResult, type DPoPSigner, type GetAccessTokenOptions, KEKVault, type LoadPermissionsOptions, LoginRequiredError, NetworkError, OAuthProtocolError, type PermissionCheck, type PermissionResult, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, type SessionEndedMessage, type StepUpOptions, type TokenBroadcast, type TokenResponse, _resetDiscoveryCache, backoffDelay, base64ToBytes, bytesToBase64Url, classifyRenewalError, createAtolBrowserAuth, createDPoPKeyManager, createTokenBroadcast, createUserManager, decodeJWTPayload, exchangeCode, extractKEKFromFragment, getAccessToken, getIdToken, getTokenExpiry, hasBroadcastSupport, hasTabLockSupport, kekBase64ToBytes, loadPermissions, parseAtolUser, permissionKey, readAuthorizationCodeCallback, refreshTokenGrant, revokeToken, stringToBase64Url, unwrapDEK, userFromTokenResponse, verifyAccessToken, verifyIdToken, withTabLock };
953
+ export { type AtolBrowserAuth, AtolBrowserAuthCleanupError, type AtolBrowserAuthConfig, type AtolSession, type AtolUser, type AuthorizationCodeCallback, AuthorizationCodeExchangeUncertainError, type BeginLoginOptions, type BroadcastMessage, type CredentialsInvalidatedMessage, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, type DPoPConfig, type DPoPKeyManager, type DPoPProofOptions, type DPoPProofResult, type DPoPSigner, type GetAccessTokenOptions, KEKVault, type LoadPermissionsOptions, LoginRequiredError, NetworkError, OAuthProtocolError, OrdinaryAuthorizationIntentConflictError, OrdinaryAuthorizationPendingError, type PermissionCheck, type PermissionResult, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, type SessionEndedMessage, type StepUpOptions, type TokenBroadcast, type TokenResponse, _resetDiscoveryCache, backoffDelay, base64ToBytes, bytesToBase64Url, classifyRenewalError, createAtolBrowserAuth, createDPoPKeyManager, createTokenBroadcast, createUserManager, decodeJWTPayload, exchangeCode, extractKEKFromFragment, getAccessToken, getIdToken, getTokenExpiry, hasBroadcastSupport, hasTabLockSupport, kekBase64ToBytes, loadPermissions, parseAtolUser, permissionKey, readAuthorizationCodeCallback, refreshTokenGrant, revokeToken, stringToBase64Url, unwrapDEK, userFromTokenResponse, verifyAccessToken, verifyIdToken, withTabLock };
package/dist/index.d.ts CHANGED
@@ -496,12 +496,13 @@ interface AtolBrowserAuth {
496
496
  */
497
497
  completeLogin(): Promise<AtolSession>;
498
498
  /**
499
- * Mint a new credential pair scoped to `organizationId`. This is a
499
+ * Mint a new credential pair scoped to `organizationId`. Pass `null` to
500
+ * require an unscoped credential pair for the same authenticated user. This is a
500
501
  * distinct prompt=none authorization transaction, never an alias for a
501
502
  * generic renewal. The previous credential pair remains active if the
502
503
  * selection fails.
503
504
  */
504
- selectOrganization(organizationId: string): Promise<AtolSession>;
505
+ selectOrganization(organizationId: string | null): Promise<AtolSession>;
505
506
  /**
506
507
  * Return the current access token, renewing it when it is inside the 60s
507
508
  * expiry window. With `opts.dpop` and DPoP active, also returns a bound
@@ -537,10 +538,10 @@ interface AtolBrowserAuth {
537
538
  */
538
539
  getEncryptionError(): Error | undefined;
539
540
  /**
540
- * Cancel the response-vault interactive login owned by the current browser
541
- * generation without ending an established session or navigating to the
542
- * issuer. Resolves only after exact server rejection and local custody
543
- * release. Unsupported auth modes and initialized/session states reject.
541
+ * Cancel the pending login owned by the current browser generation without
542
+ * ending an established session or navigating to the issuer. Resolves after
543
+ * local custody is released and any submitted authorization is rejected by
544
+ * the server. Use an uninitialized client without an established session.
544
545
  */
545
546
  cancelLogin(): Promise<void>;
546
547
  /**
@@ -621,6 +622,61 @@ interface CredentialGenerationSnapshot {
621
622
 
622
623
  declare const RESPONSE_VAULT_PROTOCOL_VERSION: 1;
623
624
 
625
+ /** Parsed, state-validated redirect result before the token exchange. */
626
+ interface AuthorizationCodeCallback {
627
+ code: string;
628
+ codeVerifier: string;
629
+ redirectUri: string;
630
+ nonce: string;
631
+ returnTo?: string;
632
+ credentialGeneration?: CredentialGenerationSnapshot;
633
+ }
634
+ /**
635
+ * Create an oidc-client-ts UserManager configured for Atol.
636
+ *
637
+ * Storage policy:
638
+ * - `userStore` is IN-MEMORY. The full User object (access token, ID
639
+ * token, and -- when `useRefreshTokens` is on -- the refresh token)
640
+ * never touches sessionStorage or localStorage, so an XSS payload
641
+ * cannot read persisted credentials after the fact. The cost is that
642
+ * a page reload starts with an empty store; the provider recovers by
643
+ * attempting a silent renew against the IdP session cookie.
644
+ * - `stateStore` stays in sessionStorage. It only holds the OIDC
645
+ * state/PKCE verifier, which must survive the same-tab redirect to
646
+ * the Atol login page and back, and is worthless to an attacker
647
+ * after the code exchange completes.
648
+ */
649
+ declare function createUserManager(authority: string, clientId: string, redirectUri: string, scope: string, audience?: string): UserManager;
650
+ /**
651
+ * Read a redirect callback without letting oidc-client-ts exchange the code.
652
+ * The matching state remains present until the caller definitively settles
653
+ * its code exchange.
654
+ */
655
+ declare function readAuthorizationCodeCallback(manager: UserManager, url: string): Promise<AuthorizationCodeCallback>;
656
+ /** Extract the access token from an oidc-client-ts User. */
657
+ declare function getAccessToken(user: User | null): string | undefined;
658
+ /** Extract the ID token from an oidc-client-ts User. */
659
+ declare function getIdToken(user: User | null): string | undefined;
660
+ /**
661
+ * Build an oidc-client-ts User from a raw /auth/token response. Used to
662
+ * write renewed tokens back into the UserManager store so `mgr.getUser()`
663
+ * and React state never disagree (e.g. a rotated-away refresh token
664
+ * lingering in the store).
665
+ *
666
+ * `expires_at` prefers the access token's own `exp` claim; falls back to
667
+ * `expires_in` relative to now when the token is opaque.
668
+ */
669
+ declare function userFromTokenResponse(tokens: TokenResponse): User;
670
+
671
+ declare class OrdinaryAuthorizationPendingError extends Error {
672
+ constructor();
673
+ }
674
+ /** An existing browser authorization must settle before its intent can change. */
675
+ declare class OrdinaryAuthorizationIntentConflictError extends Error {
676
+ readonly pendingMode: 'silent' | 'interactive';
677
+ constructor(pendingMode: 'silent' | 'interactive');
678
+ }
679
+
624
680
  /**
625
681
  * Parse Atol custom claims from a JWT token (ID token or access token).
626
682
  * Decodes the payload without verifying the signature — verification is
@@ -674,52 +730,6 @@ declare function verifyAccessToken(accessToken: string, opts: {
674
730
  /** Test-only: drop the discovery cache so a test can re-stub the IdP. */
675
731
  declare function _resetDiscoveryCache(): void;
676
732
 
677
- /** Parsed, state-validated redirect result before the token exchange. */
678
- interface AuthorizationCodeCallback {
679
- code: string;
680
- codeVerifier: string;
681
- redirectUri: string;
682
- nonce: string;
683
- returnTo?: string;
684
- credentialGeneration?: CredentialGenerationSnapshot;
685
- }
686
- /**
687
- * Create an oidc-client-ts UserManager configured for Atol.
688
- *
689
- * Storage policy:
690
- * - `userStore` is IN-MEMORY. The full User object (access token, ID
691
- * token, and -- when `useRefreshTokens` is on -- the refresh token)
692
- * never touches sessionStorage or localStorage, so an XSS payload
693
- * cannot read persisted credentials after the fact. The cost is that
694
- * a page reload starts with an empty store; the provider recovers by
695
- * attempting a silent renew against the IdP session cookie.
696
- * - `stateStore` stays in sessionStorage. It only holds the OIDC
697
- * state/PKCE verifier, which must survive the same-tab redirect to
698
- * the Atol login page and back, and is worthless to an attacker
699
- * after the code exchange completes.
700
- */
701
- declare function createUserManager(authority: string, clientId: string, redirectUri: string, scope: string, audience?: string): UserManager;
702
- /**
703
- * Read a redirect callback without letting oidc-client-ts exchange the code.
704
- * The matching state remains present until the caller definitively settles
705
- * its code exchange.
706
- */
707
- declare function readAuthorizationCodeCallback(manager: UserManager, url: string): Promise<AuthorizationCodeCallback>;
708
- /** Extract the access token from an oidc-client-ts User. */
709
- declare function getAccessToken(user: User | null): string | undefined;
710
- /** Extract the ID token from an oidc-client-ts User. */
711
- declare function getIdToken(user: User | null): string | undefined;
712
- /**
713
- * Build an oidc-client-ts User from a raw /auth/token response. Used to
714
- * write renewed tokens back into the UserManager store so `mgr.getUser()`
715
- * and React state never disagree (e.g. a rotated-away refresh token
716
- * lingering in the store).
717
- *
718
- * `expires_at` prefers the access token's own `exp` claim; falls back to
719
- * `expires_in` relative to now when the token is opaque.
720
- */
721
- declare function userFromTokenResponse(tokens: TokenResponse): User;
722
-
723
733
  /**
724
734
  * Cross-tab mutual exclusion for renewal work.
725
735
  *
@@ -940,4 +950,4 @@ declare function stringToBase64Url(input: string): string;
940
950
  */
941
951
  declare function base64ToBytes(b64: string): Uint8Array;
942
952
 
943
- export { type AtolBrowserAuth, AtolBrowserAuthCleanupError, type AtolBrowserAuthConfig, type AtolSession, type AtolUser, type AuthorizationCodeCallback, AuthorizationCodeExchangeUncertainError, type BeginLoginOptions, type BroadcastMessage, type CredentialsInvalidatedMessage, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, type DPoPConfig, type DPoPKeyManager, type DPoPProofOptions, type DPoPProofResult, type DPoPSigner, type GetAccessTokenOptions, KEKVault, type LoadPermissionsOptions, LoginRequiredError, NetworkError, OAuthProtocolError, type PermissionCheck, type PermissionResult, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, type SessionEndedMessage, type StepUpOptions, type TokenBroadcast, type TokenResponse, _resetDiscoveryCache, backoffDelay, base64ToBytes, bytesToBase64Url, classifyRenewalError, createAtolBrowserAuth, createDPoPKeyManager, createTokenBroadcast, createUserManager, decodeJWTPayload, exchangeCode, extractKEKFromFragment, getAccessToken, getIdToken, getTokenExpiry, hasBroadcastSupport, hasTabLockSupport, kekBase64ToBytes, loadPermissions, parseAtolUser, permissionKey, readAuthorizationCodeCallback, refreshTokenGrant, revokeToken, stringToBase64Url, unwrapDEK, userFromTokenResponse, verifyAccessToken, verifyIdToken, withTabLock };
953
+ export { type AtolBrowserAuth, AtolBrowserAuthCleanupError, type AtolBrowserAuthConfig, type AtolSession, type AtolUser, type AuthorizationCodeCallback, AuthorizationCodeExchangeUncertainError, type BeginLoginOptions, type BroadcastMessage, type CredentialsInvalidatedMessage, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, type DPoPConfig, type DPoPKeyManager, type DPoPProofOptions, type DPoPProofResult, type DPoPSigner, type GetAccessTokenOptions, KEKVault, type LoadPermissionsOptions, LoginRequiredError, NetworkError, OAuthProtocolError, OrdinaryAuthorizationIntentConflictError, OrdinaryAuthorizationPendingError, type PermissionCheck, type PermissionResult, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, type SessionEndedMessage, type StepUpOptions, type TokenBroadcast, type TokenResponse, _resetDiscoveryCache, backoffDelay, base64ToBytes, bytesToBase64Url, classifyRenewalError, createAtolBrowserAuth, createDPoPKeyManager, createTokenBroadcast, createUserManager, decodeJWTPayload, exchangeCode, extractKEKFromFragment, getAccessToken, getIdToken, getTokenExpiry, hasBroadcastSupport, hasTabLockSupport, kekBase64ToBytes, loadPermissions, parseAtolUser, permissionKey, readAuthorizationCodeCallback, refreshTokenGrant, revokeToken, stringToBase64Url, unwrapDEK, userFromTokenResponse, verifyAccessToken, verifyIdToken, withTabLock };