[TIL] Day 68 Flutter에서 Apple 로그인 구현하기 (Firebase 연동)

현서·2026년 3월 5일

[TIL] Flutter 9기

목록 보기
80/102

1. Apple Developer 설정

Apple 로그인은 코드보다 콘솔 설정이 80%다. (진짜임)

1-1. App ID 생성

Apple Developer →
Certificates, Identifiers & Profiles → Identifiers → App IDs → +

  • Platform: iOS
  • Bundle ID: soopkomong.com
  • Explicit 선택
  • Capability에서 Sign In with Apple 활성화
    생성 완료

1-2. Services ID 생성 (웹 인증용)

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

저장

1-3. Key 생성 (.p8 파일)

Keys → + →
Sign In with Apple 체크
생성 후 .p8 다운로드

⚠️ 이 파일은 한 번만 다운로드 가능
기록해둘 것:
Team ID
Key ID
Private Key (.p8 내용 전체)


2. Firebase 콘솔 설정

Firebase Console → Authentication → Sign-in method → Apple

입력:
Services ID → soopkomong.com.signin
Apple Team ID → 발급받은 팀ID
Key ID → 생성된 Key ID
Private Key → .p8 파일 내용 전체 복붙
저장


3. Xcode 설정

ios/Runner.xcworkspace 열기
TARGETS → Runner → Signing & Capabilities
➕ Capability → Sign in with Apple 추가
Automatically manage signing 체크


4. Flutter 패키지 설치

dependencies:
  firebase_auth: ^latest
  sign_in_with_apple: ^7.0.1

5. Domain Layer 수정

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;
}

6. Data Layer 구현

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;
  }
}

7. UI 버튼 연결

onPressed: () async {
  await ref.read(authRepositoryProvider).signInWithApple();
}

0개의 댓글