質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Flutter

Flutterは、iOSとAndroidのアプリを同じコードで開発するためのフレームワークです。オープンソースで開発言語はDart。双方のプラットフォームにおける高度な実行パフォーマンスと開発効率を提供することを目的としています。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Dart

Dartは、Googleによって開発されたJavaScriptの代替となることを目的に作られた、ウェブ向けのプログラミング言語である。

Q&A

解決済

1回答

1305閲覧

flutter × firebaseでSign in with Appleを実装できない。

takechopia

総合スコア1

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Flutter

Flutterは、iOSとAndroidのアプリを同じコードで開発するためのフレームワークです。オープンソースで開発言語はDart。双方のプラットフォームにおける高度な実行パフォーマンスと開発効率を提供することを目的としています。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Dart

Dartは、Googleによって開発されたJavaScriptの代替となることを目的に作られた、ウェブ向けのプログラミング言語である。

0グッド

0クリップ

投稿2023/02/02 09:42

編集2023/02/02 09:51

実現したいこと

  • 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
こちらのページにまとまっています🤲🏻

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

xcodeの設定がvscodeで編集中のコードに反映されていなかったようです🙌🏻

直接の解決策はよくわかっていませんが、多分githubと連携したから?
xcodeで作業中のブランチに移動して設定を修正できたためと思われます。

投稿2023/02/04 12:31

takechopia

総合スコア1

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問