Android Apple 로그인을 Firebase 웹 흐름으로

This commit is contained in:
Sn-Kinos
2026-10-08 15:44:49 +09:00
parent 586039da0a
commit 0b95454b28
4 changed files with 19 additions and 40 deletions
+9 -17
View File
@@ -69,25 +69,17 @@ fvm flutter build apk --release # build/app/outputs/flutter-apk/app-relea
fvm flutter build appbundle --release # build/app/outputs/bundle/release/app-release.aab fvm flutter build appbundle --release # build/app/outputs/bundle/release/app-release.aab
``` ```
### Android Apple 로그인 — 빌드 옵션 두 개를 꼭 넣는다 ### Android Apple 로그인 — 앱에 넣을 값 없음
Android 의 Apple 로그인은 iOS 와 달리 Apple 개발자 계정에 등록한 **서비스 ID** 와 **반환 주소**를 Android 는 Apple SDK 가 없어 Firebase 웹 흐름(`apple.com` 제공자 · `signInWithProvider`)으로 로그인한다.
빌드 때 받아야 동작한다(`lib/features/auth/social_providers.dart` `appleWebAuthenticationOptionsFromEnvironment`). 값은 모두 콘솔에 둔다 — 빌드 옵션은 없다.
둘 중 하나라도 비었거나 반환 주소가 `https://호스트` 꼴이 아니면 Apple 버튼이 비활성(「준비 중」)으로 남는다.
비밀값이 아니지만 환경별 값이라 저장소에 상수로 두지 않는다.
```bash 1. Apple 개발자 계정 「Identifiers → Services IDs」에 서비스 ID 를 만들고 「Sign in with Apple」을 켠다.
fvm flutter build apk --release \ - Domains: `<프로젝트 ID>.firebaseapp.com`
--dart-define-from-file=config/kakao.env \ - Return URLs: `https://<프로젝트 ID>.firebaseapp.com/__/auth/handler`
--dart-define=FANUZU_APPLE_SERVICE_ID=<서비스 ID> \ 2. 「Keys」에서 Sign in with Apple 키를 만들고 .p8 를 받는다(키 ID · 팀 ID 기록).
--dart-define=FANUZU_APPLE_REDIRECT_URI=<서비스 ID 에 등록한 Return URL> 3. Firebase 콘솔 Authentication → 로그인 방법 → Apple 에 서비스 ID · 팀 ID · 키 ID · 비공개 키를 넣는다.
``` 4. 확인: Android 첫 화면 Apple → 브라우저 탭에서 Apple 로그인 → 앱 HOME.
- 값은 Apple 개발자 계정 「Identifiers → Services IDs」의 식별자와 그 「Sign in with Apple → Return URLs」 항목이다.
- 반환 주소가 Apple 응답을 앱으로 돌려보내야 한다 — `sign_in_with_apple` 패키지 규약대로
`intent://callback?<응답>#Intent;package=kr.co.fanuzu.app;scheme=signinwithapple;end` 로 넘기면
`AndroidManifest.xml` 의 `SignInWithAppleCallback`(scheme `signinwithapple`)이 받는다.
- 확인: 빌드한 APK 의 첫 화면에서 Apple 버튼이 눌리는지(비활성이면 옵션 누락).
## 서명 ## 서명
-1
View File
@@ -65,7 +65,6 @@ fvm flutter build ios --no-codesign # iOS 빌드 확인
| 키 | 용도 | 없을 때 | | 키 | 용도 | 없을 때 |
|---|---|---| |---|---|---|
| `FANUZU_SHARE_BASE_URL` | 공유 링크 주소(웹 브릿지) | 공유 시 링크 없이 카드 · 문구만 보냅니다 | | `FANUZU_SHARE_BASE_URL` | 공유 링크 주소(웹 브릿지) | 공유 시 링크 없이 카드 · 문구만 보냅니다 |
| `FANUZU_APPLE_SERVICE_ID` · `FANUZU_APPLE_REDIRECT_URI` | Android 에서 Apple 로그인 | Android 의 Apple 로그인 버튼이 비활성입니다 |
| `FANUZU_EMULATOR_HOST` | 로컬 Firebase 에뮬레이터 연결(개발용) | 실서버에 연결합니다 | | `FANUZU_EMULATOR_HOST` | 로컬 Firebase 에뮬레이터 연결(개발용) | 실서버에 연결합니다 |
## 4. 테스트 ## 4. 테스트
+10 -3
View File
@@ -125,9 +125,16 @@ class AuthRepository extends ChangeNotifier {
/// 돌려준다. /// 돌려준다.
static List<SocialAuthProvider> _defaultProviders() => [ static List<SocialAuthProvider> _defaultProviders() => [
const GoogleSignInProvider(), const GoogleSignInProvider(),
AppleSignInProvider( // Android 는 Apple SDK 가 없어 Firebase 웹 흐름(`apple.com` 제공자)으로 간다 —
webAuthenticationOptions: appleWebAuthenticationOptionsFromEnvironment(), // 서비스 ID · 키는 Firebase 콘솔 Apple 제공자 설정에 두고 앱에는 값이 없다.
), if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android)
const OidcSignInProvider(
AuthProviderKind.apple,
providerId: 'apple.com',
scopes: ['email', 'name'],
)
else
const AppleSignInProvider(),
// 동의 항목은 카카오 콘솔 설정을 따른다(지금은 닉네임). 이메일(account_email)은 비즈 앱 // 동의 항목은 카카오 콘솔 설정을 따른다(지금은 닉네임). 이메일(account_email)은 비즈 앱
// 전환 후 콘솔에서 켜면 서버가 동의·인증된 값만 받는다. // 전환 후 콘솔에서 켜면 서버가 동의·인증된 값만 받는다.
KakaoSignInProvider(), KakaoSignInProvider(),
@@ -501,25 +501,6 @@ Future<T> untilAbandoned<T>(
}); });
} }
/// Apple Service ID와 callback URL은 비밀값이 아니지만 환경별 값이다.
/// 저장소에 임시 상수를 박지 않고 빌드 시 `--dart-define`으로만 받는다.
apple.WebAuthenticationOptions? appleWebAuthenticationOptionsFromEnvironment() {
const clientId = String.fromEnvironment('FANUZU_APPLE_SERVICE_ID');
const redirect = String.fromEnvironment('FANUZU_APPLE_REDIRECT_URI');
if (clientId.isEmpty || redirect.isEmpty) return null;
final redirectUri = Uri.tryParse(redirect);
if (redirectUri == null ||
!redirectUri.hasScheme ||
!redirectUri.hasAuthority) {
return null;
}
return apple.WebAuthenticationOptions(
clientId: clientId,
redirectUri: redirectUri,
);
}
AuthAccount _toAccount(fb.User? user, SocialProvider provider) => AuthAccount( AuthAccount _toAccount(fb.User? user, SocialProvider provider) => AuthAccount(
uid: user?.uid ?? '', uid: user?.uid ?? '',
provider: provider, provider: provider,