@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @firebase/app-check
|
|
2
2
|
|
|
3
|
+
## 0.6.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`8c44d5863`](https://github.com/firebase/firebase-js-sdk/commit/8c44d586355ffd2d58b6841730ebdac89229954c) [#7203](https://github.com/firebase/firebase-js-sdk/pull/7203) - Catch all ReCAPTCHA errors and, if caught, prevent App Check from making a request to the exchange endpoint.
|
|
8
|
+
|
|
3
9
|
## 0.6.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -102,6 +102,23 @@ export declare interface CustomProviderOptions {
|
|
|
102
102
|
getToken: () => Promise<AppCheckToken>;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Requests a Firebase App Check token. This method should be used
|
|
107
|
+
* only if you need to authorize requests to a non-Firebase backend.
|
|
108
|
+
*
|
|
109
|
+
* Returns limited-use tokens that are intended for use with your
|
|
110
|
+
* non-Firebase backend endpoints that are protected with
|
|
111
|
+
* <a href="https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection">
|
|
112
|
+
* Replay Protection</a>. This method
|
|
113
|
+
* does not affect the token generation behavior of the
|
|
114
|
+
* #getAppCheckToken() method.
|
|
115
|
+
*
|
|
116
|
+
* @param appCheckInstance - The App Check service instance.
|
|
117
|
+
* @returns The limited use token.
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
export declare function getLimitedUseToken(appCheckInstance: AppCheck): Promise<AppCheckTokenResult>;
|
|
121
|
+
|
|
105
122
|
/**
|
|
106
123
|
* Get the current App Check token. Attaches to the most recent
|
|
107
124
|
* in-flight request if one is present. Returns null if no token
|
package/dist/app-check.d.ts
CHANGED
|
@@ -124,6 +124,23 @@ export declare interface CustomProviderOptions {
|
|
|
124
124
|
getToken: () => Promise<AppCheckToken>;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Requests a Firebase App Check token. This method should be used
|
|
129
|
+
* only if you need to authorize requests to a non-Firebase backend.
|
|
130
|
+
*
|
|
131
|
+
* Returns limited-use tokens that are intended for use with your
|
|
132
|
+
* non-Firebase backend endpoints that are protected with
|
|
133
|
+
* <a href="https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection">
|
|
134
|
+
* Replay Protection</a>. This method
|
|
135
|
+
* does not affect the token generation behavior of the
|
|
136
|
+
* #getAppCheckToken() method.
|
|
137
|
+
*
|
|
138
|
+
* @param appCheckInstance - The App Check service instance.
|
|
139
|
+
* @returns The limited use token.
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
export declare function getLimitedUseToken(appCheckInstance: AppCheck): Promise<AppCheckTokenResult>;
|
|
143
|
+
|
|
127
144
|
/**
|
|
128
145
|
* Get the current App Check token. Attaches to the most recent
|
|
129
146
|
* in-flight request if one is present. Returns null if no token
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -915,6 +915,35 @@ function getToken$2(appCheck, forceRefresh) {
|
|
|
915
915
|
});
|
|
916
916
|
});
|
|
917
917
|
}
|
|
918
|
+
/**
|
|
919
|
+
* Internal API for limited use tokens. Skips all FAC state and simply calls
|
|
920
|
+
* the underlying provider.
|
|
921
|
+
*/
|
|
922
|
+
function getLimitedUseToken$1(appCheck) {
|
|
923
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
924
|
+
var app, provider, debugToken, token, token;
|
|
925
|
+
return __generator(this, function (_a) {
|
|
926
|
+
switch (_a.label) {
|
|
927
|
+
case 0:
|
|
928
|
+
app = appCheck.app;
|
|
929
|
+
ensureActivated(app);
|
|
930
|
+
provider = getStateReference(app).provider;
|
|
931
|
+
if (!isDebugMode()) return [3 /*break*/, 3];
|
|
932
|
+
return [4 /*yield*/, getDebugToken()];
|
|
933
|
+
case 1:
|
|
934
|
+
debugToken = _a.sent();
|
|
935
|
+
return [4 /*yield*/, exchangeToken(getExchangeDebugTokenRequest(app, debugToken), appCheck.heartbeatServiceProvider)];
|
|
936
|
+
case 2:
|
|
937
|
+
token = (_a.sent()).token;
|
|
938
|
+
return [2 /*return*/, { token: token }];
|
|
939
|
+
case 3: return [4 /*yield*/, provider.getToken()];
|
|
940
|
+
case 4:
|
|
941
|
+
token = (_a.sent()).token;
|
|
942
|
+
return [2 /*return*/, { token: token }];
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
});
|
|
946
|
+
}
|
|
918
947
|
function addTokenListener(appCheck, type, listener, onError) {
|
|
919
948
|
var app = appCheck.app;
|
|
920
949
|
var state = getStateReference(app);
|
|
@@ -1120,7 +1149,7 @@ function internalFactory(appCheck) {
|
|
|
1120
1149
|
}
|
|
1121
1150
|
|
|
1122
1151
|
var name = "@firebase/app-check";
|
|
1123
|
-
var version = "0.6.
|
|
1152
|
+
var version = "0.6.5-canary.0a27d2fbf";
|
|
1124
1153
|
|
|
1125
1154
|
/**
|
|
1126
1155
|
* @license
|
|
@@ -1239,7 +1268,15 @@ function getToken$1(app) {
|
|
|
1239
1268
|
function renderInvisibleWidget(app, siteKey, grecaptcha, container) {
|
|
1240
1269
|
var widgetId = grecaptcha.render(container, {
|
|
1241
1270
|
sitekey: siteKey,
|
|
1242
|
-
size: 'invisible'
|
|
1271
|
+
size: 'invisible',
|
|
1272
|
+
// Success callback - set state
|
|
1273
|
+
callback: function () {
|
|
1274
|
+
getStateReference(app).reCAPTCHAState.succeeded = true;
|
|
1275
|
+
},
|
|
1276
|
+
// Failure callback - set state
|
|
1277
|
+
'error-callback': function () {
|
|
1278
|
+
getStateReference(app).reCAPTCHAState.succeeded = false;
|
|
1279
|
+
}
|
|
1243
1280
|
});
|
|
1244
1281
|
var state = getStateReference(app);
|
|
1245
1282
|
state.reCAPTCHAState = __assign(__assign({}, state.reCAPTCHAState), { // state.reCAPTCHAState is set in the initialize()
|
|
@@ -1298,11 +1335,11 @@ var ReCaptchaV3Provider = /** @class */ (function () {
|
|
|
1298
1335
|
* @internal
|
|
1299
1336
|
*/
|
|
1300
1337
|
ReCaptchaV3Provider.prototype.getToken = function () {
|
|
1301
|
-
var _a, _b;
|
|
1338
|
+
var _a, _b, _c;
|
|
1302
1339
|
return __awaiter(this, void 0, void 0, function () {
|
|
1303
1340
|
var attestedClaimsToken, result, e_1;
|
|
1304
|
-
return __generator(this, function (
|
|
1305
|
-
switch (
|
|
1341
|
+
return __generator(this, function (_d) {
|
|
1342
|
+
switch (_d.label) {
|
|
1306
1343
|
case 0:
|
|
1307
1344
|
throwIfThrottled(this._throttleData);
|
|
1308
1345
|
return [4 /*yield*/, getToken$1(this._app).catch(function (_e) {
|
|
@@ -1310,18 +1347,22 @@ var ReCaptchaV3Provider = /** @class */ (function () {
|
|
|
1310
1347
|
throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
|
|
1311
1348
|
})];
|
|
1312
1349
|
case 1:
|
|
1313
|
-
attestedClaimsToken =
|
|
1314
|
-
|
|
1350
|
+
attestedClaimsToken = _d.sent();
|
|
1351
|
+
// Check if a failure state was set by the recaptcha "error-callback".
|
|
1352
|
+
if (!((_a = getStateReference(this._app).reCAPTCHAState) === null || _a === void 0 ? void 0 : _a.succeeded)) {
|
|
1353
|
+
throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
|
|
1354
|
+
}
|
|
1355
|
+
_d.label = 2;
|
|
1315
1356
|
case 2:
|
|
1316
|
-
|
|
1357
|
+
_d.trys.push([2, 4, , 5]);
|
|
1317
1358
|
return [4 /*yield*/, exchangeToken(getExchangeRecaptchaV3TokenRequest(this._app, attestedClaimsToken), this._heartbeatServiceProvider)];
|
|
1318
1359
|
case 3:
|
|
1319
|
-
result =
|
|
1360
|
+
result = _d.sent();
|
|
1320
1361
|
return [3 /*break*/, 5];
|
|
1321
1362
|
case 4:
|
|
1322
|
-
e_1 =
|
|
1323
|
-
if ((
|
|
1324
|
-
this._throttleData = setBackoff(Number((
|
|
1363
|
+
e_1 = _d.sent();
|
|
1364
|
+
if ((_b = e_1.code) === null || _b === void 0 ? void 0 : _b.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
|
|
1365
|
+
this._throttleData = setBackoff(Number((_c = e_1.customData) === null || _c === void 0 ? void 0 : _c.httpStatus), this._throttleData);
|
|
1325
1366
|
throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
|
|
1326
1367
|
time: getDurationString(this._throttleData.allowRequestsAfter - Date.now()),
|
|
1327
1368
|
httpStatus: this._throttleData.httpStatus
|
|
@@ -1385,11 +1426,11 @@ var ReCaptchaEnterpriseProvider = /** @class */ (function () {
|
|
|
1385
1426
|
* @internal
|
|
1386
1427
|
*/
|
|
1387
1428
|
ReCaptchaEnterpriseProvider.prototype.getToken = function () {
|
|
1388
|
-
var _a, _b;
|
|
1429
|
+
var _a, _b, _c;
|
|
1389
1430
|
return __awaiter(this, void 0, void 0, function () {
|
|
1390
1431
|
var attestedClaimsToken, result, e_2;
|
|
1391
|
-
return __generator(this, function (
|
|
1392
|
-
switch (
|
|
1432
|
+
return __generator(this, function (_d) {
|
|
1433
|
+
switch (_d.label) {
|
|
1393
1434
|
case 0:
|
|
1394
1435
|
throwIfThrottled(this._throttleData);
|
|
1395
1436
|
return [4 /*yield*/, getToken$1(this._app).catch(function (_e) {
|
|
@@ -1397,18 +1438,22 @@ var ReCaptchaEnterpriseProvider = /** @class */ (function () {
|
|
|
1397
1438
|
throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
|
|
1398
1439
|
})];
|
|
1399
1440
|
case 1:
|
|
1400
|
-
attestedClaimsToken =
|
|
1401
|
-
|
|
1441
|
+
attestedClaimsToken = _d.sent();
|
|
1442
|
+
// Check if a failure state was set by the recaptcha "error-callback".
|
|
1443
|
+
if (!((_a = getStateReference(this._app).reCAPTCHAState) === null || _a === void 0 ? void 0 : _a.succeeded)) {
|
|
1444
|
+
throw ERROR_FACTORY.create("recaptcha-error" /* AppCheckError.RECAPTCHA_ERROR */);
|
|
1445
|
+
}
|
|
1446
|
+
_d.label = 2;
|
|
1402
1447
|
case 2:
|
|
1403
|
-
|
|
1448
|
+
_d.trys.push([2, 4, , 5]);
|
|
1404
1449
|
return [4 /*yield*/, exchangeToken(getExchangeRecaptchaEnterpriseTokenRequest(this._app, attestedClaimsToken), this._heartbeatServiceProvider)];
|
|
1405
1450
|
case 3:
|
|
1406
|
-
result =
|
|
1451
|
+
result = _d.sent();
|
|
1407
1452
|
return [3 /*break*/, 5];
|
|
1408
1453
|
case 4:
|
|
1409
|
-
e_2 =
|
|
1410
|
-
if ((
|
|
1411
|
-
this._throttleData = setBackoff(Number((
|
|
1454
|
+
e_2 = _d.sent();
|
|
1455
|
+
if ((_b = e_2.code) === null || _b === void 0 ? void 0 : _b.includes("fetch-status-error" /* AppCheckError.FETCH_STATUS_ERROR */)) {
|
|
1456
|
+
this._throttleData = setBackoff(Number((_c = e_2.customData) === null || _c === void 0 ? void 0 : _c.httpStatus), this._throttleData);
|
|
1412
1457
|
throw ERROR_FACTORY.create("throttled" /* AppCheckError.THROTTLED */, {
|
|
1413
1458
|
time: getDurationString(this._throttleData.allowRequestsAfter - Date.now()),
|
|
1414
1459
|
httpStatus: this._throttleData.httpStatus
|
|
@@ -1701,6 +1746,24 @@ function getToken(appCheckInstance, forceRefresh) {
|
|
|
1701
1746
|
});
|
|
1702
1747
|
});
|
|
1703
1748
|
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Requests a Firebase App Check token. This method should be used
|
|
1751
|
+
* only if you need to authorize requests to a non-Firebase backend.
|
|
1752
|
+
*
|
|
1753
|
+
* Returns limited-use tokens that are intended for use with your
|
|
1754
|
+
* non-Firebase backend endpoints that are protected with
|
|
1755
|
+
* <a href="https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection">
|
|
1756
|
+
* Replay Protection</a>. This method
|
|
1757
|
+
* does not affect the token generation behavior of the
|
|
1758
|
+
* #getAppCheckToken() method.
|
|
1759
|
+
*
|
|
1760
|
+
* @param appCheckInstance - The App Check service instance.
|
|
1761
|
+
* @returns The limited use token.
|
|
1762
|
+
* @public
|
|
1763
|
+
*/
|
|
1764
|
+
function getLimitedUseToken(appCheckInstance) {
|
|
1765
|
+
return getLimitedUseToken$1(appCheckInstance);
|
|
1766
|
+
}
|
|
1704
1767
|
/**
|
|
1705
1768
|
* Wraps `addTokenListener`/`removeTokenListener` methods in an `Observer`
|
|
1706
1769
|
* pattern for public use.
|
|
@@ -1764,5 +1827,5 @@ function registerAppCheck() {
|
|
|
1764
1827
|
}
|
|
1765
1828
|
registerAppCheck();
|
|
1766
1829
|
|
|
1767
|
-
export { CustomProvider, ReCaptchaEnterpriseProvider, ReCaptchaV3Provider, getToken, initializeAppCheck, onTokenChanged, setTokenAutoRefreshEnabled };
|
|
1830
|
+
export { CustomProvider, ReCaptchaEnterpriseProvider, ReCaptchaV3Provider, getLimitedUseToken, getToken, initializeAppCheck, onTokenChanged, setTokenAutoRefreshEnabled };
|
|
1768
1831
|
//# sourceMappingURL=index.esm.js.map
|