@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/CHANGELOG.md +30 -0
- package/README.md +28 -2
- package/RESPONSE_VAULT_PROTOCOL.md +23 -3
- package/dist/index.cjs +300 -173
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -53
- package/dist/index.d.ts +63 -53
- package/dist/index.js +299 -174
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4858,6 +4858,9 @@ var ResponseVaultContext = class {
|
|
|
4858
4858
|
// src/oidc/response-vault-transport.ts
|
|
4859
4859
|
var ResponseVaultTransport = class extends ResponseVaultContext {
|
|
4860
4860
|
async bootstrapClient(authorization, mode = "create") {
|
|
4861
|
+
if (mode === "par_terminal_only" && !authorization.bootstrapAttemptCapability) {
|
|
4862
|
+
throw new NetworkError("response vault: PAR recovery attempt capability is unavailable");
|
|
4863
|
+
}
|
|
4861
4864
|
const endpoints = await this.endpointRegistry();
|
|
4862
4865
|
const requestStartedAt = Date.now();
|
|
4863
4866
|
const response = await this.postJSON(
|
|
@@ -4885,7 +4888,7 @@ var ResponseVaultTransport = class extends ResponseVaultContext {
|
|
|
4885
4888
|
if (isAuthenticatedTerminalResponse(response, envelope)) {
|
|
4886
4889
|
throw new ResponseVaultAuthenticatedTerminalError();
|
|
4887
4890
|
}
|
|
4888
|
-
if (mode
|
|
4891
|
+
if (mode !== "create" && isAuthenticatedNonterminalResponse(response, envelope)) {
|
|
4889
4892
|
throw new ResponseVaultAuthorizationBusyError();
|
|
4890
4893
|
}
|
|
4891
4894
|
if (response.status === 410 || envelope.error === "authorization_terminal") {
|
|
@@ -4905,6 +4908,23 @@ var ResponseVaultTransport = class extends ResponseVaultContext {
|
|
|
4905
4908
|
}
|
|
4906
4909
|
throw protocolError(response.status, envelope, "client bootstrap");
|
|
4907
4910
|
}
|
|
4911
|
+
async probeBootstrapTerminalStatus(authority, possibleCommittedPAR) {
|
|
4912
|
+
if (!possibleCommittedPAR && !authority.bootstrapAttemptCapability) {
|
|
4913
|
+
const challenge = await this.bootstrapClient(authority);
|
|
4914
|
+
if (!("attemptCapability" in challenge)) {
|
|
4915
|
+
throw new NetworkError("response vault: expected a bootstrap attempt challenge");
|
|
4916
|
+
}
|
|
4917
|
+
authority = { ...authority, bootstrapAttemptCapability: challenge.attemptCapability };
|
|
4918
|
+
}
|
|
4919
|
+
try {
|
|
4920
|
+
await this.bootstrapClient(authority, possibleCommittedPAR ? "par_terminal_only" : "terminal_only");
|
|
4921
|
+
} catch (error) {
|
|
4922
|
+
if (error instanceof ResponseVaultAuthenticatedTerminalError) return "terminal";
|
|
4923
|
+
if (error instanceof ResponseVaultAuthorizationBusyError) return "nonterminal";
|
|
4924
|
+
throw error;
|
|
4925
|
+
}
|
|
4926
|
+
throw new NetworkError("response vault: bootstrap terminal status is unavailable");
|
|
4927
|
+
}
|
|
4908
4928
|
async pushAuthorization(authorization, csrf) {
|
|
4909
4929
|
if (!authorization.bootstrapTerminalProof) {
|
|
4910
4930
|
throw new Error(
|
|
@@ -5078,6 +5098,26 @@ var ResponseVaultRejection = class extends ResponseVaultTransport {
|
|
|
5078
5098
|
throw new ResponseVaultAuthorizationBusyError();
|
|
5079
5099
|
}
|
|
5080
5100
|
}
|
|
5101
|
+
async probeTerminalStatus(cancellation) {
|
|
5102
|
+
const response = await this.postJSON(
|
|
5103
|
+
`${this.clientOrigin}${REJECT_PATH}`,
|
|
5104
|
+
{
|
|
5105
|
+
version: RESPONSE_VAULT_PROTOCOL_VERSION,
|
|
5106
|
+
mode: "terminal_only",
|
|
5107
|
+
transaction_id: cancellation.transactionId,
|
|
5108
|
+
client_id: cancellation.binding.clientId,
|
|
5109
|
+
tab_secret: cancellation.tabSecret,
|
|
5110
|
+
cancellation_secret: cancellation.cancellationSecret,
|
|
5111
|
+
terminal_proof: cancellation.terminalProof
|
|
5112
|
+
},
|
|
5113
|
+
"authorization terminal probe",
|
|
5114
|
+
"same-origin"
|
|
5115
|
+
);
|
|
5116
|
+
const envelope = await responseEnvelope(response);
|
|
5117
|
+
if (isAuthenticatedTerminalResponse(response, envelope)) return "terminal";
|
|
5118
|
+
if (isAuthenticatedNonterminalResponse(response, envelope)) return "nonterminal";
|
|
5119
|
+
throw protocolError(response.status, envelope, "authorization terminal probe");
|
|
5120
|
+
}
|
|
5081
5121
|
async probeTerminal(initial, claim, onExecutionClaimed) {
|
|
5082
5122
|
if (!initial.terminalProof) {
|
|
5083
5123
|
throw new Error(
|
|
@@ -5090,39 +5130,9 @@ var ResponseVaultRejection = class extends ResponseVaultTransport {
|
|
|
5090
5130
|
onExecutionClaimed?.();
|
|
5091
5131
|
let lastError;
|
|
5092
5132
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
5093
|
-
let
|
|
5094
|
-
let authenticatedNonterminal = false;
|
|
5133
|
+
let outcome;
|
|
5095
5134
|
try {
|
|
5096
|
-
|
|
5097
|
-
`${this.clientOrigin}${REJECT_PATH}`,
|
|
5098
|
-
{
|
|
5099
|
-
version: RESPONSE_VAULT_PROTOCOL_VERSION,
|
|
5100
|
-
mode: "terminal_only",
|
|
5101
|
-
transaction_id: cancellation.transactionId,
|
|
5102
|
-
client_id: cancellation.binding.clientId,
|
|
5103
|
-
tab_secret: cancellation.tabSecret,
|
|
5104
|
-
cancellation_secret: cancellation.cancellationSecret,
|
|
5105
|
-
terminal_proof: cancellation.terminalProof
|
|
5106
|
-
},
|
|
5107
|
-
"authorization terminal probe",
|
|
5108
|
-
"same-origin"
|
|
5109
|
-
);
|
|
5110
|
-
const envelope = await responseEnvelope(response);
|
|
5111
|
-
authenticatedTerminal = isAuthenticatedTerminalResponse(
|
|
5112
|
-
response,
|
|
5113
|
-
envelope
|
|
5114
|
-
);
|
|
5115
|
-
authenticatedNonterminal = isAuthenticatedNonterminalResponse(
|
|
5116
|
-
response,
|
|
5117
|
-
envelope
|
|
5118
|
-
);
|
|
5119
|
-
if (!authenticatedTerminal && !authenticatedNonterminal) {
|
|
5120
|
-
throw protocolError(
|
|
5121
|
-
response.status,
|
|
5122
|
-
envelope,
|
|
5123
|
-
"authorization terminal probe"
|
|
5124
|
-
);
|
|
5125
|
-
}
|
|
5135
|
+
outcome = await this.probeTerminalStatus(cancellation);
|
|
5126
5136
|
} catch (error) {
|
|
5127
5137
|
lastError = error;
|
|
5128
5138
|
if (attempt < 2) {
|
|
@@ -5130,7 +5140,7 @@ var ResponseVaultRejection = class extends ResponseVaultTransport {
|
|
|
5130
5140
|
}
|
|
5131
5141
|
continue;
|
|
5132
5142
|
}
|
|
5133
|
-
if (
|
|
5143
|
+
if (outcome === "terminal") {
|
|
5134
5144
|
try {
|
|
5135
5145
|
await discardResponseVaultCancellation(cancellation);
|
|
5136
5146
|
} catch (error) {
|
|
@@ -5336,6 +5346,84 @@ var ResponseVaultRejection = class extends ResponseVaultTransport {
|
|
|
5336
5346
|
}
|
|
5337
5347
|
};
|
|
5338
5348
|
|
|
5349
|
+
// src/oidc/response-vault-storage-peer-recovery.ts
|
|
5350
|
+
function isRejectionCustody(status) {
|
|
5351
|
+
return status === "rejecting" || status === "reject_retry" || status === "reject_blocked";
|
|
5352
|
+
}
|
|
5353
|
+
function isExpiredPeerRecoveryCandidate(custody) {
|
|
5354
|
+
const mode = "dpopKey" in custody ? custody.mode : custody.sourceMode;
|
|
5355
|
+
return custody.expiresAt <= Date.now() && (mode === "interactive" || isRejectionCustody(custody.status));
|
|
5356
|
+
}
|
|
5357
|
+
async function checkExpiredPeerCustody(transaction, binding, expected, requester) {
|
|
5358
|
+
const key = slotKey(binding);
|
|
5359
|
+
const slot = await requestResult(
|
|
5360
|
+
transaction.objectStore(RESPONSE_VAULT_SLOT_STORE).get(key),
|
|
5361
|
+
"expired peer slot read"
|
|
5362
|
+
);
|
|
5363
|
+
const stored = await requestResult(
|
|
5364
|
+
transaction.objectStore(RESPONSE_VAULT_RECORD_STORE).get(expected.reference.id),
|
|
5365
|
+
"expired peer custody read"
|
|
5366
|
+
);
|
|
5367
|
+
const now = Date.now();
|
|
5368
|
+
assertCredentialGenerationSnapshot(binding, requester);
|
|
5369
|
+
const authority = currentCredentialAuthority(binding);
|
|
5370
|
+
if (authority.signedOut || authority.generation !== requester.logout || expected.credentialGeneration.logout !== requester.logout || expected.credentialGeneration.tabOwner === requester.tabOwner || expected.expiresAt > now || !validSlotRecord(slot, key) || slot.referenceId !== expected.reference.id || slot.expiresAt !== expected.expiresAt) {
|
|
5371
|
+
throw new ResponseVaultExecutionBusyError();
|
|
5372
|
+
}
|
|
5373
|
+
const validatePeer = (record) => {
|
|
5374
|
+
assertCustodyRevision(expected, record.revision);
|
|
5375
|
+
if (record.status !== expected.status || record.expiresAt !== expected.expiresAt || record.credentialGeneration.logout !== expected.credentialGeneration.logout || record.credentialGeneration.tabOwner !== expected.credentialGeneration.tabOwner) {
|
|
5376
|
+
throw new ResponseVaultExecutionBusyError();
|
|
5377
|
+
}
|
|
5378
|
+
};
|
|
5379
|
+
if (expected.status === "prepared" || expected.status === "par_pending") {
|
|
5380
|
+
const record = stored;
|
|
5381
|
+
assertRecordBinding(record, expected.reference, binding, now, false, true);
|
|
5382
|
+
validatePeer(record);
|
|
5383
|
+
if (record.mode !== "interactive") throw new ResponseVaultExecutionBusyError();
|
|
5384
|
+
return {
|
|
5385
|
+
kind: record.status === "par_pending" ? "par" : "bootstrap",
|
|
5386
|
+
authority: {
|
|
5387
|
+
tabSecret: record.tabSecret,
|
|
5388
|
+
cancellationSecret: record.cancellationSecret,
|
|
5389
|
+
parIdempotencyKey: record.parIdempotencyKey,
|
|
5390
|
+
bootstrapAttemptCapability: record.bootstrapAttemptCapability
|
|
5391
|
+
}
|
|
5392
|
+
};
|
|
5393
|
+
}
|
|
5394
|
+
assertCancellationBinding(stored, expected.reference, binding, now, false, true);
|
|
5395
|
+
validatePeer(stored);
|
|
5396
|
+
if (stored.custody === "cancellation" ? !isRejectionCustody(stored.status) : stored.mode !== "interactive") {
|
|
5397
|
+
throw new ResponseVaultExecutionBusyError();
|
|
5398
|
+
}
|
|
5399
|
+
return { kind: "transaction", authority: publicCancellation(stored, expected.lifecycleEpoch) };
|
|
5400
|
+
}
|
|
5401
|
+
async function recoverExpiredPeerAuthorization(binding, expected, requester, probe) {
|
|
5402
|
+
const owner = randomOpaque();
|
|
5403
|
+
await acquireExecutionLock(expected.reference, owner, false);
|
|
5404
|
+
try {
|
|
5405
|
+
const database = await openDB();
|
|
5406
|
+
try {
|
|
5407
|
+
const read = database.transaction([RESPONSE_VAULT_RECORD_STORE, RESPONSE_VAULT_SLOT_STORE], "readonly");
|
|
5408
|
+
const candidate = await checkExpiredPeerCustody(read, binding, expected, requester);
|
|
5409
|
+
await transactionDone(read, "expired peer custody read");
|
|
5410
|
+
if (await probe(candidate) !== "terminal") {
|
|
5411
|
+
return false;
|
|
5412
|
+
}
|
|
5413
|
+
const discard = database.transaction([RESPONSE_VAULT_RECORD_STORE, RESPONSE_VAULT_SLOT_STORE], "readwrite");
|
|
5414
|
+
await checkExpiredPeerCustody(discard, binding, expected, requester);
|
|
5415
|
+
discard.objectStore(RESPONSE_VAULT_SLOT_STORE).delete(slotKey(binding));
|
|
5416
|
+
discard.objectStore(RESPONSE_VAULT_RECORD_STORE).delete(expected.reference.id);
|
|
5417
|
+
await transactionDone(discard, "terminal peer custody discard");
|
|
5418
|
+
return true;
|
|
5419
|
+
} finally {
|
|
5420
|
+
database.close();
|
|
5421
|
+
}
|
|
5422
|
+
} finally {
|
|
5423
|
+
await releaseOwnedExecutionLockIfHeld(expected.reference, owner);
|
|
5424
|
+
}
|
|
5425
|
+
}
|
|
5426
|
+
|
|
5339
5427
|
// src/oidc/response-vault-custody.ts
|
|
5340
5428
|
var ResponseVaultCustodyLayer = class extends ResponseVaultRejection {
|
|
5341
5429
|
invalidateLifecycle(rotateLogout = false) {
|
|
@@ -5662,6 +5750,18 @@ var ResponseVaultCustodyLayer = class extends ResponseVaultRejection {
|
|
|
5662
5750
|
const currentGeneration = credentialGenerationSnapshot(this.config);
|
|
5663
5751
|
const rejectionOwner = authorization.executionClaim?.owner ?? active.rejectionOwner ?? randomOpaque2();
|
|
5664
5752
|
if (!bindingMatches || authorization.credentialGeneration.tabOwner !== currentGeneration.tabOwner) {
|
|
5753
|
+
if (bindingMatches && isExpiredPeerRecoveryCandidate(authorization) && authorization.credentialGeneration.logout === currentGeneration.logout && abandonedCleanupError === void 0) {
|
|
5754
|
+
const recovered = await recoverExpiredPeerAuthorization(
|
|
5755
|
+
this.config,
|
|
5756
|
+
authorization,
|
|
5757
|
+
currentGeneration,
|
|
5758
|
+
(candidate) => candidate.kind === "transaction" ? this.probeTerminalStatus(candidate.authority) : this.probeBootstrapTerminalStatus(candidate.authority, candidate.kind === "par")
|
|
5759
|
+
);
|
|
5760
|
+
if (recovered) {
|
|
5761
|
+
this.clearActive(authorization.reference);
|
|
5762
|
+
return null;
|
|
5763
|
+
}
|
|
5764
|
+
}
|
|
5665
5765
|
failAfterCleanup(new ResponseVaultAuthorizationBusyError());
|
|
5666
5766
|
}
|
|
5667
5767
|
try {
|
|
@@ -5760,7 +5860,10 @@ var ResponseVaultCustodyLayer = class extends ResponseVaultRejection {
|
|
|
5760
5860
|
);
|
|
5761
5861
|
onExecutionClaimed?.();
|
|
5762
5862
|
try {
|
|
5763
|
-
await this.bootstrapClient(
|
|
5863
|
+
await this.bootstrapClient(
|
|
5864
|
+
claimed,
|
|
5865
|
+
claimed.status === "par_pending" ? "par_terminal_only" : "terminal_only"
|
|
5866
|
+
);
|
|
5764
5867
|
throw new Error(
|
|
5765
5868
|
"response vault: terminal bootstrap classification returned"
|
|
5766
5869
|
);
|
|
@@ -6469,6 +6572,15 @@ var OrdinaryAuthorizationPendingError = class extends Error {
|
|
|
6469
6572
|
this.name = "OrdinaryAuthorizationPendingError";
|
|
6470
6573
|
}
|
|
6471
6574
|
};
|
|
6575
|
+
var OrdinaryAuthorizationIntentConflictError = class extends Error {
|
|
6576
|
+
constructor(pendingMode) {
|
|
6577
|
+
super(
|
|
6578
|
+
"An earlier sign-in is unfinished. Retry that sign-in, or sign in from a new tab."
|
|
6579
|
+
);
|
|
6580
|
+
this.pendingMode = pendingMode;
|
|
6581
|
+
this.name = "OrdinaryAuthorizationIntentConflictError";
|
|
6582
|
+
}
|
|
6583
|
+
};
|
|
6472
6584
|
function validCanonicalSHA256(value) {
|
|
6473
6585
|
if (!CANONICAL_SHA256.test(value)) return false;
|
|
6474
6586
|
try {
|
|
@@ -7503,7 +7615,7 @@ function createBrowserAuthActions(runtime) {
|
|
|
7503
7615
|
});
|
|
7504
7616
|
}
|
|
7505
7617
|
async function selectOrganization(organizationId) {
|
|
7506
|
-
if (!CANONICAL_ULID.test(organizationId)) {
|
|
7618
|
+
if (organizationId !== null && (typeof organizationId !== "string" || !CANONICAL_ULID.test(organizationId))) {
|
|
7507
7619
|
throw new Error(
|
|
7508
7620
|
"organizationId must be a canonical ULID"
|
|
7509
7621
|
);
|
|
@@ -7522,16 +7634,17 @@ function createBrowserAuthActions(runtime) {
|
|
|
7522
7634
|
throw new StaleCredentialTransactionError();
|
|
7523
7635
|
}
|
|
7524
7636
|
const selectionEpoch = ++runtime.credentialEpoch;
|
|
7637
|
+
const expectedOrganizationId = organizationId ?? void 0;
|
|
7525
7638
|
runtime.sessionOps.clearRenewTimer();
|
|
7526
7639
|
try {
|
|
7527
7640
|
const grant = await runtime.renewalOps.renewViaIframe(
|
|
7528
|
-
|
|
7641
|
+
expectedOrganizationId,
|
|
7529
7642
|
selectionGeneration,
|
|
7530
7643
|
true
|
|
7531
7644
|
);
|
|
7532
7645
|
await runtime.credentialOps.applyAuthorizationGrant(grant, {
|
|
7533
7646
|
epoch: selectionEpoch,
|
|
7534
|
-
expectedOrganizationId
|
|
7647
|
+
expectedOrganizationId,
|
|
7535
7648
|
enforceExpectedOrganization: true,
|
|
7536
7649
|
preserveExistingTokens: false,
|
|
7537
7650
|
expectedNonce: grant.nonce,
|
|
@@ -7620,6 +7733,9 @@ function createBrowserAuthActions(runtime) {
|
|
|
7620
7733
|
try {
|
|
7621
7734
|
await runtime.manager.signoutRedirect({
|
|
7622
7735
|
post_logout_redirect_uri: runtime.postLogoutRedirectUri,
|
|
7736
|
+
// The audience is an authorization parameter, not a logout
|
|
7737
|
+
// parameter. Override oidc-client-ts's global extraQueryParams.
|
|
7738
|
+
extraQueryParams: {},
|
|
7623
7739
|
...runtime.pendingLogoutIdToken ? { id_token_hint: runtime.pendingLogoutIdToken } : {},
|
|
7624
7740
|
state: signoutState(
|
|
7625
7741
|
invalidation.logoutGeneration
|
|
@@ -7654,10 +7770,8 @@ function createBrowserAuthActions(runtime) {
|
|
|
7654
7770
|
return operation;
|
|
7655
7771
|
}
|
|
7656
7772
|
async function cancelLoginOnce() {
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
}
|
|
7660
|
-
const recoverableFailedInitialization = runtime.initPromise !== null && runtime.initRejected && runtime.failedInitCancellationAuthority !== null && !runtime.lifecycleOps.isCallbackUrl() && !runtime.lifecycleOps.isPostLogoutCallbackUrl();
|
|
7773
|
+
const responseVault = runtime.responseVault;
|
|
7774
|
+
const recoverableFailedInitialization = responseVault !== null && runtime.initPromise !== null && runtime.initRejected && runtime.failedInitCancellationAuthority !== null && !runtime.lifecycleOps.isCallbackUrl() && !runtime.lifecycleOps.isPostLogoutCallbackUrl();
|
|
7661
7775
|
if (runtime.initPromise !== null && !recoverableFailedInitialization || runtime.completeLoginPromise !== null || runtime.currentUser !== null || runtime.accessToken !== void 0 || runtime.currentIdToken !== void 0 || runtime.refreshToken !== void 0) {
|
|
7662
7776
|
throw new Error(
|
|
7663
7777
|
"cancelLogin requires an uninitialized signed-out client"
|
|
@@ -7666,17 +7780,25 @@ function createBrowserAuthActions(runtime) {
|
|
|
7666
7780
|
if (runtime.destroyed) {
|
|
7667
7781
|
throw new Error("auth client has been destroyed");
|
|
7668
7782
|
}
|
|
7783
|
+
if (!responseVault) {
|
|
7784
|
+
const generation = credentialGenerationSnapshot(
|
|
7785
|
+
runtime.credentialGenerationBinding
|
|
7786
|
+
);
|
|
7787
|
+
await runtime.ordinaryAuthorization.invalidateCurrent(generation);
|
|
7788
|
+
runtime.sessionOps.assertCredentialAuthority(generation);
|
|
7789
|
+
return;
|
|
7790
|
+
}
|
|
7669
7791
|
const markCleanupOwned = () => {
|
|
7670
7792
|
runtime.destroyAuthorizationCleanupStarted = true;
|
|
7671
7793
|
};
|
|
7672
7794
|
if (recoverableFailedInitialization) {
|
|
7673
7795
|
await cancelResponseVaultFailedInitialization(
|
|
7674
|
-
|
|
7796
|
+
responseVault,
|
|
7675
7797
|
runtime.failedInitCancellationAuthority,
|
|
7676
7798
|
markCleanupOwned
|
|
7677
7799
|
);
|
|
7678
7800
|
} else {
|
|
7679
|
-
await
|
|
7801
|
+
await responseVault.cancelLogin(markCleanupOwned);
|
|
7680
7802
|
}
|
|
7681
7803
|
if (recoverableFailedInitialization) {
|
|
7682
7804
|
runtime.initPromise = null;
|
|
@@ -8427,51 +8549,6 @@ async function settleOrdinaryAuthorization(authority, mode) {
|
|
|
8427
8549
|
}
|
|
8428
8550
|
}
|
|
8429
8551
|
|
|
8430
|
-
// src/oidc/ordinary-authorization-pre-navigation.ts
|
|
8431
|
-
function assertSubmittedCancellation(record) {
|
|
8432
|
-
if (record.preNavigationCancellationEndpoint !== `${record.issuer}/auth/par/pre-navigation-cancellation` || record.parPhase !== "submitted" || record.requestUri !== null || record.terminalProof !== null || record.rootExpiresAt !== null || record.rootExpiresAtMs !== null || record.custodyExpiresAtMs !== null || record.rejectionRequired || record.cleanupStarted) {
|
|
8433
|
-
throw new Error(
|
|
8434
|
-
"ordinary browser authorization: pre-navigation cancellation authority is invalid"
|
|
8435
|
-
);
|
|
8436
|
-
}
|
|
8437
|
-
}
|
|
8438
|
-
async function cancelSubmittedOrdinaryAuthorization(record) {
|
|
8439
|
-
assertSubmittedCancellation(record);
|
|
8440
|
-
const controller = new AbortController();
|
|
8441
|
-
const timeout = setTimeout(
|
|
8442
|
-
() => controller.abort(),
|
|
8443
|
-
SETTLEMENT_TIMEOUT_MS
|
|
8444
|
-
);
|
|
8445
|
-
try {
|
|
8446
|
-
let response;
|
|
8447
|
-
try {
|
|
8448
|
-
response = await fetch(
|
|
8449
|
-
record.preNavigationCancellationEndpoint,
|
|
8450
|
-
{
|
|
8451
|
-
method: "POST",
|
|
8452
|
-
headers: {
|
|
8453
|
-
Accept: "application/json",
|
|
8454
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
8455
|
-
},
|
|
8456
|
-
body: ordinaryAuthorizationPARBody(record),
|
|
8457
|
-
cache: "no-store",
|
|
8458
|
-
credentials: "omit",
|
|
8459
|
-
redirect: "error",
|
|
8460
|
-
referrerPolicy: "no-referrer",
|
|
8461
|
-
signal: controller.signal
|
|
8462
|
-
}
|
|
8463
|
-
);
|
|
8464
|
-
} catch {
|
|
8465
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
8466
|
-
}
|
|
8467
|
-
if (response.status !== 204 || response.headers.get("cache-control") !== "no-store" || !hasAuthenticatedOrdinaryAuthorizationSignal(response) || response.headers.get("content-type") !== null || response.body !== null) {
|
|
8468
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
8469
|
-
}
|
|
8470
|
-
} finally {
|
|
8471
|
-
clearTimeout(timeout);
|
|
8472
|
-
}
|
|
8473
|
-
}
|
|
8474
|
-
|
|
8475
8552
|
// src/oidc/ordinary-authorization-database.ts
|
|
8476
8553
|
function openOrdinaryAuthorizationDB() {
|
|
8477
8554
|
return new Promise((resolve, reject) => {
|
|
@@ -9285,6 +9362,117 @@ async function deleteOrdinaryAuthorizationRecordRevision(expected) {
|
|
|
9285
9362
|
}
|
|
9286
9363
|
}
|
|
9287
9364
|
|
|
9365
|
+
// src/oidc/ordinary-authorization-transport.ts
|
|
9366
|
+
function validOrdinaryPARResponseHeaders(response) {
|
|
9367
|
+
return response.headers.get("cache-control") === "no-store" && response.headers.get("content-type") === "application/json" && response.headers.get("atol-browser-authorization") === "v2";
|
|
9368
|
+
}
|
|
9369
|
+
async function postOrdinaryPAR(record, signal) {
|
|
9370
|
+
const startedAt = Date.now();
|
|
9371
|
+
try {
|
|
9372
|
+
const response = await fetch(record.pushedAuthorizationRequestEndpoint, {
|
|
9373
|
+
method: "POST",
|
|
9374
|
+
headers: {
|
|
9375
|
+
Accept: "application/json",
|
|
9376
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
9377
|
+
},
|
|
9378
|
+
body: ordinaryAuthorizationPARBody(record),
|
|
9379
|
+
cache: "no-store",
|
|
9380
|
+
credentials: "omit",
|
|
9381
|
+
redirect: "error",
|
|
9382
|
+
referrerPolicy: "no-referrer",
|
|
9383
|
+
signal
|
|
9384
|
+
});
|
|
9385
|
+
return { response, startedAt };
|
|
9386
|
+
} catch {
|
|
9387
|
+
throw new OrdinaryAuthorizationPendingError();
|
|
9388
|
+
}
|
|
9389
|
+
}
|
|
9390
|
+
async function bindOrdinaryPARChallenge(record, response, startedAt, signal) {
|
|
9391
|
+
if (response.status !== 428 || !validOrdinaryPARResponseHeaders(response)) {
|
|
9392
|
+
throw new OrdinaryAuthorizationPendingError();
|
|
9393
|
+
}
|
|
9394
|
+
let challengeText;
|
|
9395
|
+
try {
|
|
9396
|
+
challengeText = await readBoundedParResponse(response, signal);
|
|
9397
|
+
} catch {
|
|
9398
|
+
throw new OrdinaryAuthorizationPendingError();
|
|
9399
|
+
}
|
|
9400
|
+
const challenge = ordinaryAuthorizationAttemptChallenge(
|
|
9401
|
+
record,
|
|
9402
|
+
challengeText,
|
|
9403
|
+
startedAt
|
|
9404
|
+
);
|
|
9405
|
+
const bound = await bindOrdinaryAuthorizationAttemptCapability(
|
|
9406
|
+
record,
|
|
9407
|
+
challenge.attemptCapability,
|
|
9408
|
+
challenge.attemptExpiresAt
|
|
9409
|
+
);
|
|
9410
|
+
assertOrdinaryAuthorizationRecord(
|
|
9411
|
+
bound,
|
|
9412
|
+
record,
|
|
9413
|
+
record.credentialGeneration,
|
|
9414
|
+
record.intent
|
|
9415
|
+
);
|
|
9416
|
+
await assertOrdinaryAuthorizationRecordState(bound);
|
|
9417
|
+
return bound;
|
|
9418
|
+
}
|
|
9419
|
+
|
|
9420
|
+
// src/oidc/ordinary-authorization-pre-navigation.ts
|
|
9421
|
+
function assertSubmittedCancellation(record) {
|
|
9422
|
+
if (record.preNavigationCancellationEndpoint !== `${record.issuer}/auth/par/pre-navigation-cancellation` || record.parPhase !== "submitted" || record.requestUri !== null || record.terminalProof !== null || record.rootExpiresAt !== null || record.rootExpiresAtMs !== null || record.custodyExpiresAtMs !== null || record.rejectionRequired || record.cleanupStarted) {
|
|
9423
|
+
throw new Error(
|
|
9424
|
+
"ordinary browser authorization: pre-navigation cancellation authority is invalid"
|
|
9425
|
+
);
|
|
9426
|
+
}
|
|
9427
|
+
}
|
|
9428
|
+
async function cancelSubmittedOrdinaryAuthorization(record) {
|
|
9429
|
+
assertSubmittedCancellation(record);
|
|
9430
|
+
const controller = new AbortController();
|
|
9431
|
+
const timeout = setTimeout(
|
|
9432
|
+
() => controller.abort(),
|
|
9433
|
+
SETTLEMENT_TIMEOUT_MS
|
|
9434
|
+
);
|
|
9435
|
+
try {
|
|
9436
|
+
let submitted = record;
|
|
9437
|
+
if (record.attemptExpiresAtMs === null) {
|
|
9438
|
+
const challenge = await postOrdinaryPAR(record, controller.signal);
|
|
9439
|
+
submitted = await bindOrdinaryPARChallenge(
|
|
9440
|
+
record,
|
|
9441
|
+
challenge.response,
|
|
9442
|
+
challenge.startedAt,
|
|
9443
|
+
controller.signal
|
|
9444
|
+
);
|
|
9445
|
+
}
|
|
9446
|
+
let response;
|
|
9447
|
+
try {
|
|
9448
|
+
response = await fetch(
|
|
9449
|
+
submitted.preNavigationCancellationEndpoint,
|
|
9450
|
+
{
|
|
9451
|
+
method: "POST",
|
|
9452
|
+
headers: {
|
|
9453
|
+
Accept: "application/json",
|
|
9454
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
9455
|
+
},
|
|
9456
|
+
body: ordinaryAuthorizationPARBody(submitted),
|
|
9457
|
+
cache: "no-store",
|
|
9458
|
+
credentials: "omit",
|
|
9459
|
+
redirect: "error",
|
|
9460
|
+
referrerPolicy: "no-referrer",
|
|
9461
|
+
signal: controller.signal
|
|
9462
|
+
}
|
|
9463
|
+
);
|
|
9464
|
+
} catch {
|
|
9465
|
+
throw new OrdinaryAuthorizationPendingError();
|
|
9466
|
+
}
|
|
9467
|
+
if (response.status !== 204 || response.headers.get("cache-control") !== "no-store" || !hasAuthenticatedOrdinaryAuthorizationSignal(response) || response.headers.get("content-type") !== null || response.body !== null) {
|
|
9468
|
+
throw new OrdinaryAuthorizationPendingError();
|
|
9469
|
+
}
|
|
9470
|
+
return submitted;
|
|
9471
|
+
} finally {
|
|
9472
|
+
clearTimeout(timeout);
|
|
9473
|
+
}
|
|
9474
|
+
}
|
|
9475
|
+
|
|
9288
9476
|
// src/oidc/ordinary-authorization-cleanup.ts
|
|
9289
9477
|
var OrdinaryAuthorizationCleanupController = class {
|
|
9290
9478
|
constructor(manager, binding, storageKey) {
|
|
@@ -9358,8 +9546,8 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9358
9546
|
await this.startAndFinishCleanup(rejecting);
|
|
9359
9547
|
}
|
|
9360
9548
|
async rejectSubmittedAndCleanup(record) {
|
|
9361
|
-
await cancelSubmittedOrdinaryAuthorization(record);
|
|
9362
|
-
await this.startAndFinishCleanup(
|
|
9549
|
+
const settled = await cancelSubmittedOrdinaryAuthorization(record);
|
|
9550
|
+
await this.startAndFinishCleanup(settled);
|
|
9363
9551
|
}
|
|
9364
9552
|
async terminalOnlyAndCleanup(record) {
|
|
9365
9553
|
this.assertExactPointer(record);
|
|
@@ -9390,6 +9578,7 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9390
9578
|
}
|
|
9391
9579
|
return;
|
|
9392
9580
|
}
|
|
9581
|
+
if (pointer) this.assertExactPointer(record);
|
|
9393
9582
|
assertOrdinaryAuthorizationRecord(
|
|
9394
9583
|
record,
|
|
9395
9584
|
this.binding,
|
|
@@ -9845,12 +10034,13 @@ var OrdinaryAuthorizationAdmissionTerminalError = class extends Error {
|
|
|
9845
10034
|
}
|
|
9846
10035
|
};
|
|
9847
10036
|
async function rejectUncommittedAdmission(submitted) {
|
|
10037
|
+
let settled;
|
|
9848
10038
|
try {
|
|
9849
|
-
await cancelSubmittedOrdinaryAuthorization(submitted);
|
|
10039
|
+
settled = await cancelSubmittedOrdinaryAuthorization(submitted);
|
|
9850
10040
|
} catch {
|
|
9851
10041
|
return null;
|
|
9852
10042
|
}
|
|
9853
|
-
return startOrdinaryAuthorizationCleanup(
|
|
10043
|
+
return startOrdinaryAuthorizationCleanup(settled);
|
|
9854
10044
|
}
|
|
9855
10045
|
async function rejectOrRetainInvalidAdmission(submitted) {
|
|
9856
10046
|
const cleaning = await rejectUncommittedAdmission(submitted);
|
|
@@ -9859,9 +10049,6 @@ async function rejectOrRetainInvalidAdmission(submitted) {
|
|
|
9859
10049
|
}
|
|
9860
10050
|
throw new OrdinaryAuthorizationPendingError();
|
|
9861
10051
|
}
|
|
9862
|
-
function validPARResponseHeaders(response) {
|
|
9863
|
-
return response.headers.get("cache-control") === "no-store" && response.headers.get("content-type") === "application/json" && response.headers.get("atol-browser-authorization") === "v2";
|
|
9864
|
-
}
|
|
9865
10052
|
async function admitOrdinaryAuthorization(record) {
|
|
9866
10053
|
if (ordinaryAuthorizationRecordExpired(record)) {
|
|
9867
10054
|
if (record.parPhase === "submitted") {
|
|
@@ -9889,89 +10076,21 @@ async function admitOrdinaryAuthorization(record) {
|
|
|
9889
10076
|
PAR_TIMEOUT_MS
|
|
9890
10077
|
);
|
|
9891
10078
|
try {
|
|
9892
|
-
|
|
9893
|
-
let
|
|
9894
|
-
try {
|
|
9895
|
-
response = await fetch(
|
|
9896
|
-
submitted.pushedAuthorizationRequestEndpoint,
|
|
9897
|
-
{
|
|
9898
|
-
method: "POST",
|
|
9899
|
-
headers: {
|
|
9900
|
-
Accept: "application/json",
|
|
9901
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
9902
|
-
},
|
|
9903
|
-
body: ordinaryAuthorizationPARBody(submitted),
|
|
9904
|
-
cache: "no-store",
|
|
9905
|
-
credentials: "omit",
|
|
9906
|
-
redirect: "error",
|
|
9907
|
-
referrerPolicy: "no-referrer",
|
|
9908
|
-
signal: controller.signal
|
|
9909
|
-
}
|
|
9910
|
-
);
|
|
9911
|
-
} catch {
|
|
9912
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
9913
|
-
}
|
|
10079
|
+
const first = await postOrdinaryPAR(submitted, controller.signal);
|
|
10080
|
+
let response = first.response;
|
|
9914
10081
|
if (response.status === 428) {
|
|
9915
|
-
|
|
9916
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
9917
|
-
}
|
|
9918
|
-
let challengeText;
|
|
9919
|
-
try {
|
|
9920
|
-
challengeText = await readBoundedParResponse(
|
|
9921
|
-
response,
|
|
9922
|
-
controller.signal
|
|
9923
|
-
);
|
|
9924
|
-
} catch {
|
|
9925
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
9926
|
-
}
|
|
9927
|
-
const challenge = ordinaryAuthorizationAttemptChallenge(
|
|
9928
|
-
submitted,
|
|
9929
|
-
challengeText,
|
|
9930
|
-
requestStartedAt
|
|
9931
|
-
);
|
|
9932
|
-
submitted = await bindOrdinaryAuthorizationAttemptCapability(
|
|
10082
|
+
submitted = await bindOrdinaryPARChallenge(
|
|
9933
10083
|
submitted,
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
assertOrdinaryAuthorizationRecord(
|
|
9938
|
-
submitted,
|
|
9939
|
-
{
|
|
9940
|
-
issuer: record.issuer,
|
|
9941
|
-
clientId: record.clientId,
|
|
9942
|
-
redirectUri: record.redirectUri,
|
|
9943
|
-
scope: record.scope
|
|
9944
|
-
},
|
|
9945
|
-
record.credentialGeneration,
|
|
9946
|
-
record.intent
|
|
10084
|
+
response,
|
|
10085
|
+
first.startedAt,
|
|
10086
|
+
controller.signal
|
|
9947
10087
|
);
|
|
9948
|
-
await
|
|
9949
|
-
requestStartedAt = Date.now();
|
|
9950
|
-
try {
|
|
9951
|
-
response = await fetch(
|
|
9952
|
-
submitted.pushedAuthorizationRequestEndpoint,
|
|
9953
|
-
{
|
|
9954
|
-
method: "POST",
|
|
9955
|
-
headers: {
|
|
9956
|
-
Accept: "application/json",
|
|
9957
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
9958
|
-
},
|
|
9959
|
-
body: ordinaryAuthorizationPARBody(submitted),
|
|
9960
|
-
cache: "no-store",
|
|
9961
|
-
credentials: "omit",
|
|
9962
|
-
redirect: "error",
|
|
9963
|
-
referrerPolicy: "no-referrer",
|
|
9964
|
-
signal: controller.signal
|
|
9965
|
-
}
|
|
9966
|
-
);
|
|
9967
|
-
} catch {
|
|
9968
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
9969
|
-
}
|
|
10088
|
+
response = (await postOrdinaryPAR(submitted, controller.signal)).response;
|
|
9970
10089
|
}
|
|
9971
10090
|
if (response.status !== 201) {
|
|
9972
10091
|
throw new OrdinaryAuthorizationPendingError();
|
|
9973
10092
|
}
|
|
9974
|
-
if (!
|
|
10093
|
+
if (!validOrdinaryPARResponseHeaders(response)) {
|
|
9975
10094
|
return rejectOrRetainInvalidAdmission(submitted);
|
|
9976
10095
|
}
|
|
9977
10096
|
let responseText;
|
|
@@ -10252,9 +10371,15 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10252
10371
|
record,
|
|
10253
10372
|
this.binding,
|
|
10254
10373
|
generation,
|
|
10255
|
-
intent
|
|
10374
|
+
record.intent
|
|
10256
10375
|
);
|
|
10257
10376
|
await assertOrdinaryAuthorizationRecordState(record);
|
|
10377
|
+
if (record.intent !== intent) {
|
|
10378
|
+
const pending = parseOrdinaryAuthorizationIntent(record.intent);
|
|
10379
|
+
throw new OrdinaryAuthorizationIntentConflictError(
|
|
10380
|
+
pending.prompt === "none" ? "silent" : "interactive"
|
|
10381
|
+
);
|
|
10382
|
+
}
|
|
10258
10383
|
if (record.cleanupStarted) {
|
|
10259
10384
|
await this.callbacks.finishCleanup(record);
|
|
10260
10385
|
return null;
|
|
@@ -13610,6 +13735,6 @@ function permissionKey(action, resource) {
|
|
|
13610
13735
|
return `${action}:${resource}`;
|
|
13611
13736
|
}
|
|
13612
13737
|
|
|
13613
|
-
export { AtolBrowserAuthCleanupError, AuthorizationCodeExchangeUncertainError, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, KEKVault, LoginRequiredError, NetworkError, OAuthProtocolError, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, _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 };
|
|
13738
|
+
export { AtolBrowserAuthCleanupError, AuthorizationCodeExchangeUncertainError, DEFAULT_AUTHORIZE_TIMEOUT_MS, DEFAULT_SILENT_RENEW_RETRY_COUNT, KEKVault, LoginRequiredError, NetworkError, OAuthProtocolError, OrdinaryAuthorizationIntentConflictError, OrdinaryAuthorizationPendingError, RESPONSE_VAULT_PROTOCOL_VERSION, RecoveryAction, _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 };
|
|
13614
13739
|
//# sourceMappingURL=index.js.map
|
|
13615
13740
|
//# sourceMappingURL=index.js.map
|