You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an option to disable rejection of requests with invalid App Check token for callable functions. (#989)
Since releasing App Check integration for Callable Functions, we've received several requests from our users to make it possible turn App Check enforcement off. By default, if a request includes an App Check token, callable functions will verify the token, and - if the token is invalid - reject the request. This makes it hard for developers to onboard to App Check, especially for developers that want to "soft launch" App Check integration to measure the App Check enforcement would have on its users.
The change here adds a `runWith` option to allow requests with invalid App check token to continue to user code execution, e.g.
```js
exports.yourCallableFunction = functions.
.runWith({
allowInvalidAppCheckToken: true // Opt-out: Invalid App Check token cont. to user code.
}).
.https.onCall(
(data, context) => {
// Requests with an invalid App Check token are not rejected.
//
// context.app will be undefined if the request:
// 1) Does not include an App Check token
// 2) Includes an invalid App Check token
if (context.app == undefined) {
// Users can manually inspect raw request header to check whether an App Check
// token was provided in the request.
const rawToken = context.rawRequest.header['X-Firebase-AppCheck'];
if (rawToken == undefined) {
throw new functions.https.HttpsError(
'failed-precondition',
'The function must be called from an App Check verified app.'
);
} else {
throw new functions.https.HttpsError(
'unauthenticated',
'Provided App Check token failed to validate.'
);
}
},
}
);
```
0 commit comments