問題概要
FlutterアプリでFirebase認証を使い、Google Sign-Inを実装しています。Android版では正常に動作しますが、iOS版のみ認証時に「Error 400: invalid_request」が発生します。
エラーメッセージ
{}部分については置換済み。
エラー 400: invalid_request リクエストの詳細: response_type=code code_challenge_method=S256 nonce={省略} device_os=iOS 18.3.2 client_id={CLIENT_ID} emm_support=1 gpsdk=gid-7.1.0 gidenv=ios state={省略} redirect_uri={REVERSED_CLIENT_ID}:/oauth2callback code_challenge={省略} include_granted_scopes=true access_type=offline scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile openid flowName=GeneralOAuthFlow
前提
- Firebase AuthenticationでGoogleサインインを有効化済み
- Android側端末では実端末、エミュレータともGoogleサインインの正常動作確認済み(ログイン成功)。ios側ではどちらもエラー発生(アプリがクラッシュするわけではなく、エラーが出る)。
- iOS端末については複数端末、複数アカウントで同事象が発生することを確認済み。
- GoogleService-Info.plistはGoogleサインインを有効化後にダウンロードし、xcodeからios/Runner配下に格納済み。
- AppCheckについて、Android側、ios側とも有効化済みであり、適用APIはFirebase Authentication、Google Identity for iOS等。
環境情報
- Flutter: 3.29.2
- firebase_auth: ^5.5.1
- google_sign_in: ^6.1.5
- iOS: 18.3.2
- Xcode: 最新版
実装コード
dart
1// lib/repository/fireauth/sign_in_with_google_repository.dart 2Future<dynamic> signInWithGoogle() async { 3 try { 4 //Google認証フローを起動する 5 final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn(); 6 if (googleUser == null) { 7 debugPrint('Google sign in: User cancelled'); 8 throw const AppException( 9 message: 'ログインをキャンセルしました。', 10 ); 11 } 12 13 final googleAuth = await googleUser.authentication; 14 15 final credential = GoogleAuthProvider.credential( 16 accessToken: googleAuth.accessToken, 17 idToken: googleAuth.idToken, 18 ); 19 UserCredential userCredential = 20 await FirebaseAuth.instance.signInWithCredential(credential); 21 22 return userCredential; 23 } catch (e) { 24 // エラー処理省略 25 } 26}
Info.plist設定
xml
1<key>CFBundleURLTypes</key> 2<array> 3 <dict> 4 <key>CFBundleTypeRole</key> 5 <string>Editor</string> 6 <key>CFBundleURLSchemes</key> 7 <array> 8 <string>{REVERSED_CLIENT_ID}</string> 9 </array> 10 </dict> 11</array> 12<key>GIDClientID</key> 13<string>{CLIENT_ID}</string>
試した解決策
GoogleSignIn()
をパラメータなしで使用- ソースコードの方で直接
clientId
パラメータを設定 scopes
パラメータを追加(email, profile)- firebaseのiosプロジェクトを一度削除し、再作成、再連携。
FirebaseやGoogle Cloud Consoleでの設定を含めてどのように解決すべきでしょうか?
下記でも同じ質問をしています。
firebase - FlutterでiOS版のみGoogle Sign-In認証でError 400: invalid_requestが発生する問題 - スタック・オーバーフロー

あなたの回答
tips
プレビュー