앱 체크가 사용자에게 미치는 영향을 이해하고 계속 진행할 준비가 되면 앱 체크 적용을 사용 설정할 수 있습니다.
호출 가능한 Cloud Functions에서 앱 체크 토큰 요구사항을 적용하려면 함수를 수정하여 아래와 같이 유효한 앱 체크 토큰이 있는지 확인하세요. 적용을 사용 설정하면 확인되지 않은 모든 요청이 거부됩니다.
프로젝트의
firebase-functions
종속 항목을 버전 4.0.0 이상으로 업데이트합니다.npm install firebase-functions@">=4.0.0"
프로젝트의
firebase-admin
종속 항목을 버전 9.8.0 이상으로 업데이트합니다.npm install firebase-admin@">=9.8.0"
함수의
enforceAppCheck
런타임 옵션을true
로 설정합니다.exports.yourCallableFunction = functions. .runWith({ enforceAppCheck: true // Requests without valid App Check tokens will be rejected. }) .https.onCall((data, context) => { // Your function logic follows. });
함수에
context.app
검사를 추가합니다.context.app
이 정의되어 있지 않으면 함수는 실패해야 합니다.exports.yourCallableFunction = functions.https.onCall((data, context) => { // context.app will be undefined if the request doesn't include an // App Check token. (If the request includes an invalid App Check // token, the request will be rejected with HTTP error 401.) if (context.app == undefined) { throw new functions.https.HttpsError( 'failed-precondition', 'The function must be called from an App Check verified app.') } // Your function logic follows. });
함수를 다시 배포합니다.
firebase deploy --only functions
이러한 변경사항이 배포되면 호출 가능한 Cloud Functions에 유효한 앱 체크 토큰이 필요합니다. Cloud Functions 클라이언트 SDK는 호출 가능 함수를 호출할 때 앱 체크 토큰을 자동으로 연결합니다.