[Flutter] #2 로그인 페이지 구글연동
지난번 만들었던 로그인페이지에 구글 로그인서비스를 연동시킨다.
순서대로 정리하자면,
1. 🔧 Google Sign-In 세팅
(1) Google API Console 설정
• OAuth 클라이언트 생성
• iOS 번들 ID 등록 (com.example.app2Client)
• 생성된 클라이언트 ID 및 리디렉션 URI 확인
(2) google_sign_in 패키지 설치
dependencies:
google_sign_in: ^6.1.5
2. 📱 iOS 설정
(1) ios/Runner/Info.plist 수정
• Google Sign-In 용 URL Scheme 등록
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.1034xxxxxxxxxxxx</string>
</array>
</dict>
</array>
(2) AppDelegate.swift 수정
• GoogleSignIn 모듈 import
• 클라이언트 ID 등록 및 URL 처리 추가
import GoogleSignIn
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: ...
) -> Bool {
GIDSignIn.sharedInstance.configuration = GIDConfiguration(
clientID: "YOUR_IOS_CLIENT_ID"
)
return super.application(...)
}
override func application(_ app: UIApplication, open url: URL, ...) -> Bool {
return GIDSignIn.sharedInstance.handle(url)
}
3. 🧪 Flutter 코드 구성
✅ AuthService 구현
• Google 로그인 실행
• 토큰 출력 (백엔드와의 연동은 추후 추가)
class AuthService {
final GoogleSignIn _googleSignIn = GoogleSignIn();
Future<bool> authenticateWithBackend() async {
final googleUser = await _googleSignIn.signIn();
final googleAuth = await googleUser?.authentication;
print('idToken: ${googleAuth?.idToken}');
return googleUser != null;
}
}
✅ 로그인 버튼 위젯 구현
class GoogleLoginButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return OutlinedButton(
onPressed: () async {
final success = await AuthService().authenticateWithBackend();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(success ? '로그인 성공!' : '로그인 실패')),
);
},
child: Text('Sign in with Google'),
);
}
}
4. 🧠 트러블슈팅
❌ 시뮬레이터에서 앱 꺼짐 (Crash)
• GIDSignIn.sharedInstance.handle(url) 미설정 → 앱 종료됨
• AppDelegate에서 URL 처리 메서드 추가 후 해결
❓ info.plist, AppDelegate에 있는 클라이언트 ID 노출돼도 괜찮을까?
• ✅ Google OAuth 클라이언트 ID는 공개되어도 괜찮은 정보
• 중요한 건 클라이언트 시크릿 / 서버 인증 로직이므로 git 업로드 OK
5. 🔐 보안 및 Git 관리
• .gitignore에 .plist 및 민감 정보 자동 제외는 ❌
→ 직접 GoogleService-Info.plist는 업로드 여부 관리할 것
• .dart_tool, build/, .idea/ 등은 자동 제외되므로 걱정 X
7. 🤔 다음 작업 (To-Do)
• 로그인 이후 사용자 정보로 백엔드 회원가입 여부 확인
• 신규 사용자면 추가 정보 입력 화면 연결
• Android 세팅도 동일하게 적용
• 로그인 상태 유지 및 자동 로그인 처리