@atol-sh/js 0.4.1 → 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 +20 -0
- package/README.md +28 -2
- package/RESPONSE_VAULT_PROTOCOL.md +23 -3
- package/dist/index.cjs +297 -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 +296 -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,
|
|
@@ -7657,10 +7770,8 @@ function createBrowserAuthActions(runtime) {
|
|
|
7657
7770
|
return operation;
|
|
7658
7771
|
}
|
|
7659
7772
|
async function cancelLoginOnce() {
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
}
|
|
7663
|
-
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();
|
|
7664
7775
|
if (runtime.initPromise !== null && !recoverableFailedInitialization || runtime.completeLoginPromise !== null || runtime.currentUser !== null || runtime.accessToken !== void 0 || runtime.currentIdToken !== void 0 || runtime.refreshToken !== void 0) {
|
|
7665
7776
|
throw new Error(
|
|
7666
7777
|
"cancelLogin requires an uninitialized signed-out client"
|
|
@@ -7669,17 +7780,25 @@ function createBrowserAuthActions(runtime) {
|
|
|
7669
7780
|
if (runtime.destroyed) {
|
|
7670
7781
|
throw new Error("auth client has been destroyed");
|
|
7671
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
|
+
}
|
|
7672
7791
|
const markCleanupOwned = () => {
|
|
7673
7792
|
runtime.destroyAuthorizationCleanupStarted = true;
|
|
7674
7793
|
};
|
|
7675
7794
|
if (recoverableFailedInitialization) {
|
|
7676
7795
|
await cancelResponseVaultFailedInitialization(
|
|
7677
|
-
|
|
7796
|
+
responseVault,
|
|
7678
7797
|
runtime.failedInitCancellationAuthority,
|
|
7679
7798
|
markCleanupOwned
|
|
7680
7799
|
);
|
|
7681
7800
|
} else {
|
|
7682
|
-
await
|
|
7801
|
+
await responseVault.cancelLogin(markCleanupOwned);
|
|
7683
7802
|
}
|
|
7684
7803
|
if (recoverableFailedInitialization) {
|
|
7685
7804
|
runtime.initPromise = null;
|
|
@@ -8430,51 +8549,6 @@ async function settleOrdinaryAuthorization(authority, mode) {
|
|
|
8430
8549
|
}
|
|
8431
8550
|
}
|
|
8432
8551
|
|
|
8433
|
-
// src/oidc/ordinary-authorization-pre-navigation.ts
|
|
8434
|
-
function assertSubmittedCancellation(record) {
|
|
8435
|
-
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) {
|
|
8436
|
-
throw new Error(
|
|
8437
|
-
"ordinary browser authorization: pre-navigation cancellation authority is invalid"
|
|
8438
|
-
);
|
|
8439
|
-
}
|
|
8440
|
-
}
|
|
8441
|
-
async function cancelSubmittedOrdinaryAuthorization(record) {
|
|
8442
|
-
assertSubmittedCancellation(record);
|
|
8443
|
-
const controller = new AbortController();
|
|
8444
|
-
const timeout = setTimeout(
|
|
8445
|
-
() => controller.abort(),
|
|
8446
|
-
SETTLEMENT_TIMEOUT_MS
|
|
8447
|
-
);
|
|
8448
|
-
try {
|
|
8449
|
-
let response;
|
|
8450
|
-
try {
|
|
8451
|
-
response = await fetch(
|
|
8452
|
-
record.preNavigationCancellationEndpoint,
|
|
8453
|
-
{
|
|
8454
|
-
method: "POST",
|
|
8455
|
-
headers: {
|
|
8456
|
-
Accept: "application/json",
|
|
8457
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
8458
|
-
},
|
|
8459
|
-
body: ordinaryAuthorizationPARBody(record),
|
|
8460
|
-
cache: "no-store",
|
|
8461
|
-
credentials: "omit",
|
|
8462
|
-
redirect: "error",
|
|
8463
|
-
referrerPolicy: "no-referrer",
|
|
8464
|
-
signal: controller.signal
|
|
8465
|
-
}
|
|
8466
|
-
);
|
|
8467
|
-
} catch {
|
|
8468
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
8469
|
-
}
|
|
8470
|
-
if (response.status !== 204 || response.headers.get("cache-control") !== "no-store" || !hasAuthenticatedOrdinaryAuthorizationSignal(response) || response.headers.get("content-type") !== null || response.body !== null) {
|
|
8471
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
8472
|
-
}
|
|
8473
|
-
} finally {
|
|
8474
|
-
clearTimeout(timeout);
|
|
8475
|
-
}
|
|
8476
|
-
}
|
|
8477
|
-
|
|
8478
8552
|
// src/oidc/ordinary-authorization-database.ts
|
|
8479
8553
|
function openOrdinaryAuthorizationDB() {
|
|
8480
8554
|
return new Promise((resolve, reject) => {
|
|
@@ -9288,6 +9362,117 @@ async function deleteOrdinaryAuthorizationRecordRevision(expected) {
|
|
|
9288
9362
|
}
|
|
9289
9363
|
}
|
|
9290
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
|
+
|
|
9291
9476
|
// src/oidc/ordinary-authorization-cleanup.ts
|
|
9292
9477
|
var OrdinaryAuthorizationCleanupController = class {
|
|
9293
9478
|
constructor(manager, binding, storageKey) {
|
|
@@ -9361,8 +9546,8 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9361
9546
|
await this.startAndFinishCleanup(rejecting);
|
|
9362
9547
|
}
|
|
9363
9548
|
async rejectSubmittedAndCleanup(record) {
|
|
9364
|
-
await cancelSubmittedOrdinaryAuthorization(record);
|
|
9365
|
-
await this.startAndFinishCleanup(
|
|
9549
|
+
const settled = await cancelSubmittedOrdinaryAuthorization(record);
|
|
9550
|
+
await this.startAndFinishCleanup(settled);
|
|
9366
9551
|
}
|
|
9367
9552
|
async terminalOnlyAndCleanup(record) {
|
|
9368
9553
|
this.assertExactPointer(record);
|
|
@@ -9393,6 +9578,7 @@ var OrdinaryAuthorizationCleanupController = class {
|
|
|
9393
9578
|
}
|
|
9394
9579
|
return;
|
|
9395
9580
|
}
|
|
9581
|
+
if (pointer) this.assertExactPointer(record);
|
|
9396
9582
|
assertOrdinaryAuthorizationRecord(
|
|
9397
9583
|
record,
|
|
9398
9584
|
this.binding,
|
|
@@ -9848,12 +10034,13 @@ var OrdinaryAuthorizationAdmissionTerminalError = class extends Error {
|
|
|
9848
10034
|
}
|
|
9849
10035
|
};
|
|
9850
10036
|
async function rejectUncommittedAdmission(submitted) {
|
|
10037
|
+
let settled;
|
|
9851
10038
|
try {
|
|
9852
|
-
await cancelSubmittedOrdinaryAuthorization(submitted);
|
|
10039
|
+
settled = await cancelSubmittedOrdinaryAuthorization(submitted);
|
|
9853
10040
|
} catch {
|
|
9854
10041
|
return null;
|
|
9855
10042
|
}
|
|
9856
|
-
return startOrdinaryAuthorizationCleanup(
|
|
10043
|
+
return startOrdinaryAuthorizationCleanup(settled);
|
|
9857
10044
|
}
|
|
9858
10045
|
async function rejectOrRetainInvalidAdmission(submitted) {
|
|
9859
10046
|
const cleaning = await rejectUncommittedAdmission(submitted);
|
|
@@ -9862,9 +10049,6 @@ async function rejectOrRetainInvalidAdmission(submitted) {
|
|
|
9862
10049
|
}
|
|
9863
10050
|
throw new OrdinaryAuthorizationPendingError();
|
|
9864
10051
|
}
|
|
9865
|
-
function validPARResponseHeaders(response) {
|
|
9866
|
-
return response.headers.get("cache-control") === "no-store" && response.headers.get("content-type") === "application/json" && response.headers.get("atol-browser-authorization") === "v2";
|
|
9867
|
-
}
|
|
9868
10052
|
async function admitOrdinaryAuthorization(record) {
|
|
9869
10053
|
if (ordinaryAuthorizationRecordExpired(record)) {
|
|
9870
10054
|
if (record.parPhase === "submitted") {
|
|
@@ -9892,89 +10076,21 @@ async function admitOrdinaryAuthorization(record) {
|
|
|
9892
10076
|
PAR_TIMEOUT_MS
|
|
9893
10077
|
);
|
|
9894
10078
|
try {
|
|
9895
|
-
|
|
9896
|
-
let
|
|
9897
|
-
try {
|
|
9898
|
-
response = await fetch(
|
|
9899
|
-
submitted.pushedAuthorizationRequestEndpoint,
|
|
9900
|
-
{
|
|
9901
|
-
method: "POST",
|
|
9902
|
-
headers: {
|
|
9903
|
-
Accept: "application/json",
|
|
9904
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
9905
|
-
},
|
|
9906
|
-
body: ordinaryAuthorizationPARBody(submitted),
|
|
9907
|
-
cache: "no-store",
|
|
9908
|
-
credentials: "omit",
|
|
9909
|
-
redirect: "error",
|
|
9910
|
-
referrerPolicy: "no-referrer",
|
|
9911
|
-
signal: controller.signal
|
|
9912
|
-
}
|
|
9913
|
-
);
|
|
9914
|
-
} catch {
|
|
9915
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
9916
|
-
}
|
|
10079
|
+
const first = await postOrdinaryPAR(submitted, controller.signal);
|
|
10080
|
+
let response = first.response;
|
|
9917
10081
|
if (response.status === 428) {
|
|
9918
|
-
|
|
9919
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
9920
|
-
}
|
|
9921
|
-
let challengeText;
|
|
9922
|
-
try {
|
|
9923
|
-
challengeText = await readBoundedParResponse(
|
|
9924
|
-
response,
|
|
9925
|
-
controller.signal
|
|
9926
|
-
);
|
|
9927
|
-
} catch {
|
|
9928
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
9929
|
-
}
|
|
9930
|
-
const challenge = ordinaryAuthorizationAttemptChallenge(
|
|
9931
|
-
submitted,
|
|
9932
|
-
challengeText,
|
|
9933
|
-
requestStartedAt
|
|
9934
|
-
);
|
|
9935
|
-
submitted = await bindOrdinaryAuthorizationAttemptCapability(
|
|
10082
|
+
submitted = await bindOrdinaryPARChallenge(
|
|
9936
10083
|
submitted,
|
|
9937
|
-
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
assertOrdinaryAuthorizationRecord(
|
|
9941
|
-
submitted,
|
|
9942
|
-
{
|
|
9943
|
-
issuer: record.issuer,
|
|
9944
|
-
clientId: record.clientId,
|
|
9945
|
-
redirectUri: record.redirectUri,
|
|
9946
|
-
scope: record.scope
|
|
9947
|
-
},
|
|
9948
|
-
record.credentialGeneration,
|
|
9949
|
-
record.intent
|
|
10084
|
+
response,
|
|
10085
|
+
first.startedAt,
|
|
10086
|
+
controller.signal
|
|
9950
10087
|
);
|
|
9951
|
-
await
|
|
9952
|
-
requestStartedAt = Date.now();
|
|
9953
|
-
try {
|
|
9954
|
-
response = await fetch(
|
|
9955
|
-
submitted.pushedAuthorizationRequestEndpoint,
|
|
9956
|
-
{
|
|
9957
|
-
method: "POST",
|
|
9958
|
-
headers: {
|
|
9959
|
-
Accept: "application/json",
|
|
9960
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
9961
|
-
},
|
|
9962
|
-
body: ordinaryAuthorizationPARBody(submitted),
|
|
9963
|
-
cache: "no-store",
|
|
9964
|
-
credentials: "omit",
|
|
9965
|
-
redirect: "error",
|
|
9966
|
-
referrerPolicy: "no-referrer",
|
|
9967
|
-
signal: controller.signal
|
|
9968
|
-
}
|
|
9969
|
-
);
|
|
9970
|
-
} catch {
|
|
9971
|
-
throw new OrdinaryAuthorizationPendingError();
|
|
9972
|
-
}
|
|
10088
|
+
response = (await postOrdinaryPAR(submitted, controller.signal)).response;
|
|
9973
10089
|
}
|
|
9974
10090
|
if (response.status !== 201) {
|
|
9975
10091
|
throw new OrdinaryAuthorizationPendingError();
|
|
9976
10092
|
}
|
|
9977
|
-
if (!
|
|
10093
|
+
if (!validOrdinaryPARResponseHeaders(response)) {
|
|
9978
10094
|
return rejectOrRetainInvalidAdmission(submitted);
|
|
9979
10095
|
}
|
|
9980
10096
|
let responseText;
|
|
@@ -10255,9 +10371,15 @@ var OrdinaryBrowserAuthorization = class {
|
|
|
10255
10371
|
record,
|
|
10256
10372
|
this.binding,
|
|
10257
10373
|
generation,
|
|
10258
|
-
intent
|
|
10374
|
+
record.intent
|
|
10259
10375
|
);
|
|
10260
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
|
+
}
|
|
10261
10383
|
if (record.cleanupStarted) {
|
|
10262
10384
|
await this.callbacks.finishCleanup(record);
|
|
10263
10385
|
return null;
|
|
@@ -13613,6 +13735,6 @@ function permissionKey(action, resource) {
|
|
|
13613
13735
|
return `${action}:${resource}`;
|
|
13614
13736
|
}
|
|
13615
13737
|
|
|
13616
|
-
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 };
|
|
13617
13739
|
//# sourceMappingURL=index.js.map
|
|
13618
13740
|
//# sourceMappingURL=index.js.map
|