[Flutter] Firebase Appcheck 설치방법
프로젝트에서 Firebase의 Firestore Database와 Storage를 사용하고 있는데
보안강화를 위해 AppCheck를 설치해야겠다 싶어 설치하는 과정을 기록해보았다.
Mac OS 기준이며 다른 플랫폼은 https://firebase.google.com/docs/cli?authuser=1&hl=ko#setup_update_cli를 참고해서 Firebase CLi를 설치후 진행하면 될거같다.
1. Firebase CLi 설치 한다.
터미널에 다음과 같이 입력한다.
curl -sL https://firebase.tools | bash
2. firebase CLi에 로그인하여 Firebase CLI 테스트를 진행한다.
터미널에 다음과 같이 입력한다.
firebase login
3. flutterfire_cli을 설치한다.
터미널에 다음과 같이 입력한다.
dart pub global activate flutterfire_cli
다음과 같이 에러가 발생한다.
Package flutterfire_cli is currently active at version 0.2.7.
The package flutterfire_cli is already activated at newest available version.
To recompile executables, first run `dart pub global deactivate flutterfire_cli`.
Installed executable flutterfire.
Warning: Pub installs executables into $HOME/.pub-cache/bin, which is not on your path.
You can fix that by adding this to your shell's config file (.bashrc, .bash_profile, etc.):
export PATH="$PATH":"$HOME/.pub-cache/bin"
Activated flutterfire_cli 0.2.7.
그렇다면 터미널에서
vi ~/.zshrc
입력후 i를 눌러 insert모드로 변경후
export PATH="$PATH":"$HOME/.pub-cache/bin"
를 복사하여 붙여놓고 esc를 누르고 shift + ; 를 눌러 wq를 입력후 엔터 쳐서 나온다.
그리고 다시
dart pub global activate flutterfire_cli
입력했을때 다음과 같이 뜬다면 flutterfire_cli 설치가 정상적으로 된 것이다.
Package flutterfire_cli is currently active at version 0.2.7.
The package flutterfire_cli is already activated at newest available version.
To recompile executables, first run `dart pub global deactivate flutterfire_cli`.
Installed executable flutterfire.
Activated flutterfire_cli 0.2.7.
4. 그다음 flutter 프로젝트 디렉토리에서 flutterfire configure를 터미널에서 입력하여 flutterfire를 설정해준다.
flutterfire configure
다음과 같이 에러가 발생하는 경우 터미널을 닫고 다시 열어서 입력하면 정상적으로 진행되는걸 확인할수있다.
zsh: command not found: flutterfire
5. flutter 프로젝트 폴더에서 firebase_app_check를 추가해준다.
flutter pub add firebase_app_check
6. 그다음 lib/main.dart 에 가서 main 함수에 다음과 같이 추가한다.
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate(
webRecaptchaSiteKey: 'recaptcha-v3-site-key',
androidProvider: AndroidProvider.debug,
);
runApp(App());
}
웹을 사용하지 않는다면 webRecapchaSiteKey를 과감히 지우고
웹도 배포한다면 https://kodean.tistory.com/24 를 참고하여 SiteKey를 생성후 붙여넣는다.
7. firebase 프로젝트에서 AppCheck 메뉴에 들어가서 각각 API를 클릭하여 적용을 클릭하여 AppCheck를 활성화 후 확인한다.
그리고 firebase에서 appcheck 화면에 들어가서 등록 버튼을 눌러 각각 디바이스 appcheck를 등록해준다.
Semantic Issue (Xcode): 'new' is unavailable
설치 후 빌드시 이러한 에러가 뜬다면 아래 링크를 참조하여 수정하면 정상적으로 빌드가 됩니다.
[Flutter] firebase app_check 0.1.2 설치 후 Semantic Issue (Xcode): 'new' is unavailable 에러 발생시
Launching lib/main.dart on iPhone 14 in debug mode... main.dart:1 Xcode build done. 16.9s Failed to build iOS app Semantic Issue (Xcode): 'new' is unavailable /Users/dean/.pub-cache/hosted/pub.dev/firebase_app_check-0.1.2/ios/Classes/FLTAppCheckProvider.m:
kodean.tistory.com
ios 시뮬레이터에서 app_check 디버깅을 원한다면 하단 링크의 글을 참고하세요
[Flutter] ios 시뮬레이터에서 firebase_app_check 사용방법
실컷 설치해두고 ios 시뮬레이터에서 디버깅을 하니 firestore_app_check가 정상적으로 작동해서 차단당해버렸다.. 시뮬레이터에서 firestore_app_check를 하면 안되는 것이 맞다! 하지만 디바이스를 꽂아
kodean.tistory.com