@firebase/app-check 0.6.4 → 0.6.5-canary.0a27d2fbf
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 +6 -0
- package/dist/app-check-public.d.ts +17 -0
- package/dist/app-check.d.ts +17 -0
- package/dist/esm/index.esm.js +86 -23
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/index.esm2017.js +62 -9
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/api.d.ts +16 -0
- package/dist/esm/src/internal-api.d.ts +5 -0
- package/dist/esm/src/recaptcha.d.ts +2 -0
- package/dist/esm/src/state.d.ts +1 -0
- package/dist/index.cjs.js +86 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/api.d.ts +16 -0
- package/dist/src/internal-api.d.ts +5 -0
- package/dist/src/recaptcha.d.ts +2 -0
- package/dist/src/state.d.ts +1 -0
- package/package.json +6 -6
package/dist/index.cjs.js
CHANGED
|
@@ -919,6 +919,35 @@ function getToken$2(appCheck, forceRefresh) {
|
|
|
919
919
|
});
|
|
920
920
|
});
|
|
921
921
|
}
|
|
922
|
+
/**
|
|
923
|
+
* Internal API for limited use tokens. Skips all FAC state and simply calls
|
|
924
|
+
* the underlying provider.
|
|
925
|
+
*/
|
|
926
|
+
function getLimitedUseToken$1(appCheck) {
|
|
927
|
+
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
928
|
+
var app, provider, debugToken, token, token;
|
|
929
|
+
return tslib.__generator(this, function (_a) {
|
|
930
|
+
switch (_a.label) {
|
|
931
|
+
case 0:
|
|
932
|
+
app = appCheck.app;
|
|
933
|
+
ensureActivated(app);
|
|
934
|
+
provider = getStateReference(app).provider;
|
|
935
|
+
if (!isDebugMode()) return [3 /*break*/, 3];
|
|
936
|
+
return [4 /*yield*/, getDebugToken()];
|
|
937
|
+
case 1:
|
|
938
|
+
debugToken = _a.sent();
|
|
939
|
+
return [4 /*yield*/, exchangeToken(getExchangeDebugTokenRequest(app, debugToken), appCheck.heartbeatServiceProvider)];
|
|
940
|
+
case 2:
|
|
941
|
+
token = (_a.sent()).token;
|
|
942
|
+
return [2 /*return*/, { token: token }];
|
|
943
|
+
case 3: return [4 /*yield*/, provider.getToken()];
|
|
944
|
+
case 4:
|
|
945
|
+
token = (_a.sent()).token;
|
|
946
|
+
return [2 /*return*/, { token: token }];
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
});
|
|
950
|
+
}
|
|
922
951
|
function addTokenListener(appCheck, type, listener, onError) {
|
|
923
952
|
var app = appCheck.app;
|
|
924
953
|
var state = getStateReference(app);
|
|
@@ -1124,7 +1153,7 @@ function internalFactory(appCheck) {
|
|
|
1124
1153
|
}
|
|
1125
1154
|
|
|
1126
1155
|
var name = "@firebase/app-check";
|
|
1127
|
-
var version = "0.6.
|
|
1156
|
+
var version = "0.6.5-canary.0a27d2fbf";
|
|
1128
1157
|
|
|
1129
1158
|
/**
|
|
1130
1159
|
* @license
|
|
@@ -1243,7 +1272,15 @@ function getToken$1(app) {
|
|
|
1243
1272
|
function renderInvisibleWidget(app, siteKey, grecaptcha, container) {
|
|
1244
1273
|
var widgetId = grecaptcha.render(container, {
|
|
1245
1274
|
sitekey: siteKey,
|
|
1246
|
-
size: 'invisible'
|
|
1275
|
+
size: 'invisible',
|
|
1276
|
+
// Success callback - set state
|
|
1277
|
+
callback: function () {
|
|
1278
|
+
getStateReference(app).reCAPTCHAState.succeeded = true;
|
|
1279
|
+
},
|
|
1280
|
+
// Failure callback - set state
|
|
1281
|
+
'error-callback': function () {
|
|
1282
|
+
getStateReference(app).reCAPTCHAState.succeeded = false;
|
|
1283
|
+
}
|
|
1247
1284
|
});
|
|
1248
1285
|
var state = getStateReference(app);
|
|
1249
1286
|
state.reCAPTCHAState = tslib.__assign(tslib.__assign({}, state.reCAPTCHAState), { // state.reCAPTCHAState is set in the initialize()
|
|
@@ -1302,11 +1339,11 @@ var ReCaptchaV3Provider = /** @class */ (function () {
|
|
|
1302
1339
|
* @internal
|
|
1303
1340
|
*/
|
|
1304
1341
|
ReCaptchaV3Provider.prototype.getToken = function () {
|
|
1305
|
-
var _a, _b;
|
|
1342
|
+
var _a, _b, _c;
|
|
1306
1343
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1307
1344
|
var attestedClaimsToken, result, e_1;
|
|
1308
|
-
return tslib.__generator(this, function (
|
|
1309
|
-
switch (
|
|
1345
|
+
return tslib.__generator(this, function (_d) {
|
|
1346
|
+
switch (_d.label) {
|
|
1310
1347
|
case 0:
|
|
1311
1348
|
throwIfThrottled(this._throttleData);
|
|
1312
1349
|
return [4 /*yield*/, getToken$1(this._app).catch(function (_e) {
|
|
@@ -1314,18 +1351,22 @@ var ReCaptchaV3Provider = /** @class */ (function () {
|
|
|
1314
1351
|
throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
|
|
1315
1352
|
})];
|
|
1316
1353
|
case 1:
|
|
1317
|
-
attestedClaimsToken =
|
|
1318
|
-
|
|
1354
|
+
attestedClaimsToken = _d.sent();
|
|
1355
|
+
// Check if a failure state was set by the recaptcha "error-callback".
|
|
1356
|
+
if (!((_a = getStateReference(this._app).reCAPTCHAState) === null || _a === void 0 ? void 0 : _a.succeeded)) {
|
|
1357
|
+
throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
|
|
1358
|
+
}
|
|
1359
|
+
_d.label = 2;
|
|
1319
1360
|
case 2:
|
|
1320
|
-
|
|
1361
|
+
_d.trys.push([2, 4, , 5]);
|
|
1321
1362
|
return [4 /*yield*/, exchangeToken(getExchangeRecaptchaV3TokenRequest(this._app, attestedClaimsToken), this._heartbeatServiceProvider)];
|
|
1322
1363
|
case 3:
|
|
1323
|
-
result =
|
|
1364
|
+
result = _d.sent();
|
|
1324
1365
|
return [3 /*break*/, 5];
|
|
1325
1366
|
case 4:
|
|
1326
|
-
e_1 =
|
|
1327
|
-
if ((
|
|
1328
|
-
this._throttleData = setBackoff(Number((
|
|
1367
|
+
e_1 = _d.sent();
|
|
1368
|
+
if ((_b = e_1.code) === null || _b === void 0 ? void 0 : _b.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
|
|
1369
|
+
this._throttleData = setBackoff(Number((_c = e_1.customData) === null || _c === void 0 ? void 0 : _c.httpStatus), this._throttleData);
|
|
1329
1370
|
throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
|
|
1330
1371
|
time: getDurationString(this._throttleData.allowRequestsAfter - Date.now()),
|
|
1331
1372
|
httpStatus: this._throttleData.httpStatus
|
|
@@ -1389,11 +1430,11 @@ var ReCaptchaEnterpriseProvider = /** @class */ (function () {
|
|
|
1389
1430
|
* @internal
|
|
1390
1431
|
*/
|
|
1391
1432
|
ReCaptchaEnterpriseProvider.prototype.getToken = function () {
|
|
1392
|
-
var _a, _b;
|
|
1433
|
+
var _a, _b, _c;
|
|
1393
1434
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
1394
1435
|
var attestedClaimsToken, result, e_2;
|
|
1395
|
-
return tslib.__generator(this, function (
|
|
1396
|
-
switch (
|
|
1436
|
+
return tslib.__generator(this, function (_d) {
|
|
1437
|
+
switch (_d.label) {
|
|
1397
1438
|
case 0:
|
|
1398
1439
|
throwIfThrottled(this._throttleData);
|
|
1399
1440
|
return [4 /*yield*/, getToken$1(this._app).catch(function (_e) {
|
|
@@ -1401,18 +1442,22 @@ var ReCaptchaEnterpriseProvider = /** @class */ (function () {
|
|
|
1401
1442
|
throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
|
|
1402
1443
|
})];
|
|
1403
1444
|
case 1:
|
|
1404
|
-
attestedClaimsToken =
|
|
1405
|
-
|
|
1445
|
+
attestedClaimsToken = _d.sent();
|
|
1446
|
+
// Check if a failure state was set by the recaptcha "error-callback".
|
|
1447
|
+
if (!((_a = getStateReference(this._app).reCAPTCHAState) === null || _a === void 0 ? void 0 : _a.succeeded)) {
|
|
1448
|
+
throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
|
|
1449
|
+
}
|
|
1450
|
+
_d.label = 2;
|
|
1406
1451
|
case 2:
|
|
1407
|
-
|
|
1452
|
+
_d.trys.push([2, 4, , 5]);
|
|
1408
1453
|
return [4 /*yield*/, exchangeToken(getExchangeRecaptchaEnterpriseTokenRequest(this._app, attestedClaimsToken), this._heartbeatServiceProvider)];
|
|
1409
1454
|
case 3:
|
|
1410
|
-
result =
|
|
1455
|
+
result = _d.sent();
|
|
1411
1456
|
return [3 /*break*/, 5];
|
|
1412
1457
|
case 4:
|
|
1413
|
-
e_2 =
|
|
1414
|
-
if ((
|
|
1415
|
-
this._throttleData = setBackoff(Number((
|
|
1458
|
+
e_2 = _d.sent();
|
|
1459
|
+
if ((_b = e_2.code) === null || _b === void 0 ? void 0 : _b.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
|
|
1460
|
+
this._throttleData = setBackoff(Number((_c = e_2.customData) === null || _c === void 0 ? void 0 : _c.httpStatus), this._throttleData);
|
|
1416
1461
|
throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
|
|
1417
1462
|
time: getDurationString(this._throttleData.allowRequestsAfter - Date.now()),
|
|
1418
1463
|
httpStatus: this._throttleData.httpStatus
|
|
@@ -1705,6 +1750,24 @@ function getToken(appCheckInstance, forceRefresh) {
|
|
|
1705
1750
|
});
|
|
1706
1751
|
});
|
|
1707
1752
|
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Requests a Firebase App Check token. This method should be used
|
|
1755
|
+
* only if you need to authorize requests to a non-Firebase backend.
|
|
1756
|
+
*
|
|
1757
|
+
* Returns limited-use tokens that are intended for use with your
|
|
1758
|
+
* non-Firebase backend endpoints that are protected with
|
|
1759
|
+
* <a href="https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection">
|
|
1760
|
+
* Replay Protection</a>. This method
|
|
1761
|
+
* does not affect the token generation behavior of the
|
|
1762
|
+
* #getAppCheckToken() method.
|
|
1763
|
+
*
|
|
1764
|
+
* @param appCheckInstance - The App Check service instance.
|
|
1765
|
+
* @returns The limited use token.
|
|
1766
|
+
* @public
|
|
1767
|
+
*/
|
|
1768
|
+
function getLimitedUseToken(appCheckInstance) {
|
|
1769
|
+
return getLimitedUseToken$1(appCheckInstance);
|
|
1770
|
+
}
|
|
1708
1771
|
/**
|
|
1709
1772
|
* Wraps `addTokenListener`/`removeTokenListener` methods in an `Observer`
|
|
1710
1773
|
* pattern for public use.
|
|
@@ -1771,6 +1834,7 @@ registerAppCheck();
|
|
|
1771
1834
|
exports.CustomProvider = CustomProvider;
|
|
1772
1835
|
exports.ReCaptchaEnterpriseProvider = ReCaptchaEnterpriseProvider;
|
|
1773
1836
|
exports.ReCaptchaV3Provider = ReCaptchaV3Provider;
|
|
1837
|
+
exports.getLimitedUseToken = getLimitedUseToken;
|
|
1774
1838
|
exports.getToken = getToken;
|
|
1775
1839
|
exports.initializeAppCheck = initializeAppCheck;
|
|
1776
1840
|
exports.onTokenChanged = onTokenChanged;
|