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