GoogleProvider class
구글 로그인 Provider
Google Sign-In을 위한 Provider입니다.
주요 제약사항
1. iOS에서 iosClientId 필수
iOS 플랫폼에서는 반드시 iosClientId가 필요합니다.
Google Cloud Console에서 iOS OAuth 2.0 클라이언트 ID를 생성하세요.
GoogleConfig(
iosClientId: 'xxx.apps.googleusercontent.com', // iOS 필수
serverClientId: 'xxx.apps.googleusercontent.com', // 백엔드 연동 시
)
2. refreshToken 미제공
Google Sign-In은 refresh token을 클라이언트에 제공하지 않습니다.
refreshToken() 호출 시 silent sign-in을 시도합니다.
// UI 없이 기존 세션으로 로그인 시도
final result = await kAuth.refreshToken(AuthProvider.google);
// 실패하면 다시 로그인 필요
if (!result.success) {
await kAuth.signIn(AuthProvider.google);
}
3. 서버 연동 시 serverClientId 설정
백엔드에서 토큰을 검증하려면 serverClientId가 필요합니다.
GoogleConfig(
serverClientId: 'xxx.apps.googleusercontent.com', // 웹 클라이언트 ID
)
4. 플랫폼별 설정
iOS (ios/Runner/Info.plist)
<key>GIDClientID</key>
<string>YOUR_IOS_CLIENT_ID</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.YOUR_CLIENT_ID</string>
</array>
</dict>
</array>
Android (android/app/build.gradle)
- google-services.json 파일 추가
- SHA-1 인증서 지문 등록
토큰 구조
| 토큰 | 설명 |
|---|---|
accessToken |
OAuth 액세스 토큰 (scope 요청 시에만) |
idToken |
JWT 형식의 ID 토큰 (사용자 정보 포함) |
refreshToken |
미제공 (서버에서 관리 필요) |
사용 예제
final result = await kAuth.signIn(AuthProvider.google);
result.fold(
onSuccess: (user) {
print('이름: ${user.displayName}');
print('이메일: ${user.email}');
print('프로필: ${user.avatar}');
// 백엔드로 idToken 전송
await myServer.verifyGoogleToken(result.idToken!);
},
onFailure: (failure) => print(failure.message),
);
- Implemented types
Constructors
- GoogleProvider(GoogleConfig config)
Properties
- config → GoogleConfig
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
initialize(
) → Future< void> -
Provider 초기화
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refreshToken(
) → Future< AuthResult> -
구글 토큰 갱신 (조용한 로그인)
override
-
signIn(
) → Future< AuthResult> -
구글 로그인 실행
override
-
signOut(
) → Future< AuthResult> -
구글 로그아웃
override
-
toString(
) → String -
A string representation of this object.
inherited
-
unlink(
) → Future< AuthResult> -
구글 연결 해제 (탈퇴)
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited