Apple 로그인은 코드보다 콘솔 설정이 80%다. (진짜임)
Apple Developer →
Certificates, Identifiers & Profiles → Identifiers → App IDs → +
Identifiers → Services IDs → +
Description: soopkomong Sign In
Identifier: soopkomong.com.signin
생성 후 클릭 → Configure
Web Authentication 설정
Primary App ID: soopkomong.com
Domains:
soopkomong.firebaseapp.com
Return URL:
https://soopkomong.firebaseapp.com/__/auth/handler
저장
Keys → + →
Sign In with Apple 체크
생성 후 .p8 다운로드
⚠️ 이 파일은 한 번만 다운로드 가능
기록해둘 것:
Team ID
Key ID
Private Key (.p8 내용 전체)
Firebase Console → Authentication → Sign-in method → Apple
입력:
Services ID → soopkomong.com.signin
Apple Team ID → 발급받은 팀ID
Key ID → 생성된 Key ID
Private Key → .p8 파일 내용 전체 복붙
저장
ios/Runner.xcworkspace 열기
TARGETS → Runner → Signing & Capabilities
➕ Capability → Sign in with Apple 추가
Automatically manage signing 체크
dependencies:
firebase_auth: ^latest
sign_in_with_apple: ^7.0.1
auth_repository.dart
abstract class AuthRepository {
Stream<AppUser?> get authStateChanges;
Future<AppUser?> signInWithGoogle();
Future<AppUser?> signInWithKakao();
Future<AppUser?> signInWithApple(); // 추가
Future<void> signOut();
AppUser? get currentUser;
}
auth_repository_impl.dart
import 'package:firebase_auth/firebase_auth.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
Future<AppUser?> signInWithApple() async {
try {
final appleCredential =
await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
);
final oauthCredential =
OAuthProvider("apple.com").credential(
idToken: appleCredential.identityToken,
accessToken: appleCredential.authorizationCode,
);
final userCredential =
await _firebaseAuth.signInWithCredential(oauthCredential);
return _mapFirebaseUser(userCredential.user);
} catch (e) {
rethrow;
}
}
onPressed: () async {
await ref.read(authRepositoryProvider).signInWithApple();
}