実現したいこと
- flutter × firebaseでSign in with Appleを実装する
前提
- xcode
- flutter
- firebase
- vscode
で、iPad向けのアプリを作成してます。
$ flutter run
を実行し、
ログイン画面でsign in with appleボタンを押すと下記エラーが発生します。(上下どちらも)
$ flutter build ios $ flutter install -d 0
また、上記コマンドを実行して実機で試すと、見た目上、無反応になります。
発生している問題・エラーメッセージ
Unhandled Exception: SignInWithAppleAuthorizationError(AuthorizationErrorCode.unknown, The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1000.)) #0 MethodChannelSignInWithApple.getAppleIDCredential
該当のソースコード
https://zenn.dev/flutteruniv_dev/articles/b92482ca1fd693
こちらの記事を参考に進めており、下記ログイン画面のコードにはコピペ後てを入れていません🙌🏻
dart
1import 'package:firebase_auth/firebase_auth.dart'; 2import 'package:flutter/material.dart'; 3import 'package:flutter_signin_button/button_list.dart'; 4import 'package:flutter_signin_button/button_view.dart'; 5import 'package:sign_in_with_apple/sign_in_with_apple.dart'; 6import 'package:provider/provider.dart'; 7 8import 'package:keyboard_planner_front/providers/page.dart'; 9import 'package:keyboard_planner_front/page/weekly.dart'; 10 11class LoginTemplate extends StatefulWidget { 12 const LoginTemplate({Key? key}) : super(key: key); 13 14 15 State<LoginTemplate> createState() => _LoginTemplate(); 16} 17 18class _LoginTemplate extends State<LoginTemplate> { 19 // 公式のを参考に作ったユーザー登録の関数 20 Future<UserCredential> signInWithApple() async { 21 print('AppSignInを実行'); 22 23 final rawNonce = generateNonce(); 24 25 // 現在サインインしているAppleアカウントのクレデンシャルを要求する。 26 final appleCredential = await SignInWithApple.getAppleIDCredential( 27 scopes: [ 28 AppleIDAuthorizationScopes.email, 29 AppleIDAuthorizationScopes.fullName, 30 ], 31 ); 32 print('クレデンシャル'); 33 print(appleCredential); 34 // Apple から返されたクレデンシャルから `OAuthCredential` を作成します。 35 final oauthCredential = OAuthProvider("apple.com").credential( 36 idToken: appleCredential.identityToken, 37 rawNonce: rawNonce, 38 ); 39 print(appleCredential); 40 // Firebaseでユーザーにサインインします。もし、先ほど生成したnonceが 41 // が `appleCredential.identityToken` の nonce と一致しない場合、サインインに失敗します。 42 return await FirebaseAuth.instance.signInWithCredential(oauthCredential); 43 } 44 45 // 上のとほぼ一緒。登録とログインができる。 46 Future<UserCredential> appleSignIn() async { 47 print('AppSignInを実行'); 48 // To prevent replay attacks with the credential returned from Apple, we 49 // include a nonce in the credential request. When signing in with 50 // Firebase, the nonce in the id token returned by Apple, is expected to 51 // match the sha256 hash of `rawNonce`. 52 final rawNonce = generateNonce(); 53 54 // Request credential for the currently signed in Apple account. 55 final appleCredential = await SignInWithApple.getAppleIDCredential( 56 scopes: [ 57 AppleIDAuthorizationScopes.email, 58 AppleIDAuthorizationScopes.fullName, 59 ], 60 ); 61 print(appleCredential); 62 // Create an `OAuthCredential` from the credential returned by Apple. 63 final oauthCredential = OAuthProvider("apple.com").credential( 64 idToken: appleCredential.identityToken, 65 rawNonce: rawNonce, 66 ); 67 // ここに画面遷移をするコードを書く! 68 Provider.of<CurrentPage>(context, listen: false).setCurrentPage(Pages.week); 69 Navigator.push( 70 context, 71 PageRouteBuilder( 72 pageBuilder: (_, __, ___) => const WeeklyPage(), 73 transitionDuration: const Duration(seconds: 0), 74 )); 75 print(appleCredential); 76 // Sign in the user with Firebase. If the nonce we generated earlier does 77 // not match the nonce in `appleCredential.identityToken`, sign in will fail. 78 return await FirebaseAuth.instance.signInWithCredential(oauthCredential); 79 } 80 81 82 Widget build(BuildContext context) { 83 return Scaffold( 84 appBar: AppBar( 85 title: const Text('AppleSignIn'), 86 ), 87 body: Center( 88 child: Column( 89 mainAxisAlignment: MainAxisAlignment.center, 90 children: [ 91 const Text('新規登録用です。'), 92 const SizedBox(height: 20), 93 Container( 94 width: 200, 95 height: 30, 96 child: SignInButton( 97 Buttons.Apple, 98 onPressed: () async { 99 signInWithApple(); 100 }, 101 ), 102 ), 103 const SizedBox(height: 20), 104 const Text('ログイン用です。'), 105 const SizedBox(height: 20), 106 Container( 107 width: 200, 108 height: 30, 109 child: SignInButton( 110 Buttons.Apple, 111 onPressed: () async { 112 appleSignIn(); 113 }, 114 ), 115 ), 116 ], 117 ), 118 )); 119 } 120} 121
pubspec.yaml
1environment: 2 sdk: ">=2.17.3 <3.0.0" 3 4dependencies: 5 flutter: 6 sdk: flutter 7 8 cupertino_icons: ^1.0.2 9 flutter_signin_button: ^2.0.0 10 sign_in_with_apple: ^4.3.0 11 firebase_core: ^2.4.1 12 firebase_auth: ^4.2.5
xcode
firebase
GoogleService-Info.plist
試したこと
https://12px.com/blog/2021/03/flutter-clean/
こちらの記事を参考に、キャッシュのクリアやxcodeの再起動など試しました。
補足情報(FW/ツールのバージョンなど)
関係ないと思いますが、一応m1 macです。
使用しているパッケージのドキュメントなども、
https://zenn.dev/flutteruniv_dev/articles/b92482ca1fd693
こちらのページにまとまっています🤲🏻

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。