「Unity/AppleAuth/FirebaseAuth連携」の版間の差分
(→UnityでiOSビルド時に、GoogleService-Info.plistで、REVERSED_CLIENT_IDエラーが出る場合) |
(→認証処理について) |
||
(同じ利用者による、間の20版が非表示) | |||
行1: | 行1: | ||
− | ==firebaseページのAuthenticationで、Appleを追加== | + | ==準備== |
+ | appstoreにプロジェクトは用意しなくても接続はできる。 | ||
+ | |||
+ | 以下は準備する。 | ||
+ | |||
+ | ===firebaseページのAuthenticationで、Appleを追加=== | ||
https://console.firebase.google.com/u/0/?hl=ja から、指定のfirebaseプロジェクトを選択し、 | https://console.firebase.google.com/u/0/?hl=ja から、指定のfirebaseプロジェクトを選択し、 | ||
Authenticationで、ログイン方法タブを選択して、新しいプロバイダに、Appleを追加する。 | Authenticationで、ログイン方法タブを選択して、新しいプロバイダに、Appleを追加する。 | ||
+ | |||
+ | ===firebaseの設定をapple側へ追加する=== | ||
+ | firebaseで指定のプロジェクトを開き、 | ||
+ | Sign In with Apple: App ID Configurationの | ||
+ | Server-to-Server Notification Endpointにfirebaseauthのauth/handerの値を設定する | ||
+ | |||
+ | https://developer.apple.com/account/resources | ||
+ | |||
+ | 公式:https://firebase.google.com/docs/auth/ios/apple?hl=ja | ||
==FirebaseAuthとAppleIdの連携スクリプト== | ==FirebaseAuthとAppleIdの連携スクリプト== | ||
行32: | 行46: | ||
対応方法 | 対応方法 | ||
https://developer.apple.com/account/ Identifiersで、 "Sign in with Apple"にチェックを付ける。 | https://developer.apple.com/account/ Identifiersで、 "Sign in with Apple"にチェックを付ける。 | ||
+ | |||
+ | xcodeの"Signing & Capabilities"タブを選択して、"Capability"ボタンを押し、リストからSign in with Appleを選択。 | ||
+ | |||
+ | 参考:https://toconakis.tech/ios-sign-in-with-apple/ | ||
==xcode実行時にIDEPreferLogStreaming=YESが出るとき== | ==xcode実行時にIDEPreferLogStreaming=YESが出るとき== | ||
行41: | 行59: | ||
xcodeメニューのProduct/Scheme/Edit Scheme/Run/Arguments/Environment Variable | xcodeメニューのProduct/Scheme/Edit Scheme/Run/Arguments/Environment Variable | ||
+をクリック | +をクリック | ||
− | + | ||
− | + | Name | |
+ | IDEPreferLogStreaming | ||
+ | Value | ||
+ | YES | ||
==xcode実行時にerror: attach by pid '9493' failedが出るとき== | ==xcode実行時にerror: attach by pid '9493' failedが出るとき== | ||
行52: | 行73: | ||
1. | 1. | ||
− | + | 開発用途であれば、adhoc証明書から、development証明書に切り替え。adhocなどは、xcode直ビルドじゃなくて、testflightとかにあげないとだめかも。 | |
2. | 2. | ||
− | + | xcodeメニューのProductで、CleanBuildFolderを実行する。 | |
3. | 3. | ||
− | + | もしくは、pc再起動。 | |
4. | 4. | ||
なおらなければ、xcodeメニューのwindow/device and simurator/open consoleからログを確認する | なおらなければ、xcodeメニューのwindow/device and simurator/open consoleからログを確認する | ||
+ | |||
+ | 1で、うまくいった。 | ||
+ | |||
+ | ==xcode実行時に"The identity provider configuration is not found."エラーが出るとき== | ||
+ | エラー詳細 | ||
+ | <pre> | ||
+ | One or more errors occurred. (The identity provider configuration is not found.) ---> Firebase.FirebaseException: The identity provider configuration is not found. | ||
+ | </pre> | ||
+ | firebaseのauthのログイン方法に、Appleを追加する | ||
+ | |||
+ | ==認証処理について== | ||
+ | <pre> | ||
+ | auth.SignInWithCredentialAsync(credential).ContinueWith(task => | ||
+ | { | ||
+ | if (task.IsCanceled || task.IsFaulted) | ||
+ | { | ||
+ | Debug.Log("error.message:" + task.Exception.Message); | ||
+ | </pre> | ||
+ | ===Exceptionで、"Invalid OAuth"がでるとき=== | ||
+ | エラー詳細 | ||
+ | One or more errors occurred. (Invalid OAuth response from apple.com) | ||
+ | 対応方法 | ||
+ | |||
+ | nonceと、authorizationCodeを追加する。 | ||
+ | |||
+ | Login時 | ||
+ | <pre> | ||
+ | var identityToken = Encoding.UTF8.GetString(appleIdCredential.IdentityToken); | ||
+ | var authorizationCode = Encoding.UTF8.GetString(appleIdCredential.AuthorizationCode); | ||
+ | var firebaseCredential = OAuthProvider.GetCredential( | ||
+ | "apple.com", | ||
+ | identityToken, | ||
+ | rawNonce, | ||
+ | authorizationCode); | ||
+ | this.firebaseAuth.SignInWithCredentialAsync(firebaseCredential) | ||
+ | .ContinueWithOnMainThread(task => HandleSignInWithUser(task, firebaseAuthCallback)); | ||
+ | </pre> | ||
+ | QuickLogin時 | ||
+ | <pre> | ||
+ | var rawNonce = GenerateRandomString(32); | ||
+ | var nonce = GenerateSHA256NonceFromRawNonce(rawNonce); | ||
+ | var quickLoginArgs = new AppleAuthQuickLoginArgs(nonce); | ||
+ | this.appleAuthManager.QuickLogin( | ||
+ | quickLoginArgs, | ||
+ | credential => | ||
+ | { | ||
+ | </pre> | ||
+ | |||
+ | apple-signin-unity公式:https://github.com/lupidan/apple-signin-unity/wiki/Sign-in-with-Apple-Unity-Plugin:-Working-with-Firebase | ||
+ | |||
+ | 参考:https://qiita.com/magosys/items/161a48ee00b6e3b00755 | ||
+ | |||
+ | ===Exceptionで、SHA256 hash of the raw nonceのエラーが出るとき=== | ||
+ | エラー例 | ||
+ | "" does not match the SHA256 hash of the raw nonce "" in the request.) | ||
+ | 対応方法 | ||
+ | nonceが正しいか確認する。 |
2025年8月13日 (水) 18:32時点における最新版
目次
- 1 準備
- 2 FirebaseAuthとAppleIdの連携スクリプト
- 3 UnityでiOSビルド時に、GoogleService-Info.plistで、REVERSED_CLIENT_IDエラーが出る場合
- 4 xcode実行時の-7026エラーが出るとき
- 5 xcode実行時にIDEPreferLogStreaming=YESが出るとき
- 6 xcode実行時にerror: attach by pid '9493' failedが出るとき
- 7 xcode実行時に"The identity provider configuration is not found."エラーが出るとき
- 8 認証処理について
準備
appstoreにプロジェクトは用意しなくても接続はできる。
以下は準備する。
firebaseページのAuthenticationで、Appleを追加
https://console.firebase.google.com/u/0/?hl=ja から、指定のfirebaseプロジェクトを選択し、 Authenticationで、ログイン方法タブを選択して、新しいプロバイダに、Appleを追加する。
firebaseの設定をapple側へ追加する
firebaseで指定のプロジェクトを開き、 Sign In with Apple: App ID Configurationの Server-to-Server Notification Endpointにfirebaseauthのauth/handerの値を設定する
https://developer.apple.com/account/resources
公式:https://firebase.google.com/docs/auth/ios/apple?hl=ja
FirebaseAuthとAppleIdの連携スクリプト
Firebase公式:https://firebase.google.com/docs/auth/unity/apple?hl=ja&authuser=0
apple-signin-unity公式:https://github.com/lupidan/apple-signin-unity/wiki/Sign-in-with-Apple-Unity-Plugin:-Working-with-Firebase
https://toconakis.tech/ios-sign-in-with-apple/
https://goropocha.hatenablog.com/entry/2021/03/27/174352
UnityでiOSビルド時に、GoogleService-Info.plistで、REVERSED_CLIENT_IDエラーが出る場合
エラー詳細
Error building Player: GoogleService-Info.plist file missing REVERSED_CLIENT_ID, Google Sign-In will fail to initialize.
Assets/GoogleService-Info.plist
<key>REVERSED_CLIENT_ID</key> <string>dummy</string>
追加する
参考:https://baba-s.hatenablog.com/entry/2024/06/13/111553
xcode実行時の-7026エラーが出るとき
エラー詳細
Sign in with apple throws Authorization failed: Error Domain=AKAuthenticationError Code=-7026
対応方法 https://developer.apple.com/account/ Identifiersで、 "Sign in with Apple"にチェックを付ける。
xcodeの"Signing & Capabilities"タブを選択して、"Capability"ボタンを押し、リストからSign in with Appleを選択。
参考:https://toconakis.tech/ios-sign-in-with-apple/
xcode実行時にIDEPreferLogStreaming=YESが出るとき
エラー詳細
Logging Error: Failed to initialize logging system due to time out. Log messages may be missing. If this issue persists, try setting IDEPreferLogStreaming=YES in the active scheme actions environment variables.
対応方法 xcodeメニューのProduct/Scheme/Edit Scheme/Run/Arguments/Environment Variable +をクリック
Name
IDEPreferLogStreaming
Value
YES
xcode実行時にerror: attach by pid '9493' failedが出るとき
エラー詳細
error: attach by pid '9493' failed -- attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
対応方法
1. 開発用途であれば、adhoc証明書から、development証明書に切り替え。adhocなどは、xcode直ビルドじゃなくて、testflightとかにあげないとだめかも。
2. xcodeメニューのProductで、CleanBuildFolderを実行する。
3. もしくは、pc再起動。
4. なおらなければ、xcodeメニューのwindow/device and simurator/open consoleからログを確認する
1で、うまくいった。
xcode実行時に"The identity provider configuration is not found."エラーが出るとき
エラー詳細
One or more errors occurred. (The identity provider configuration is not found.) ---> Firebase.FirebaseException: The identity provider configuration is not found.
firebaseのauthのログイン方法に、Appleを追加する
認証処理について
auth.SignInWithCredentialAsync(credential).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { Debug.Log("error.message:" + task.Exception.Message);
Exceptionで、"Invalid OAuth"がでるとき
エラー詳細
One or more errors occurred. (Invalid OAuth response from apple.com)
対応方法
nonceと、authorizationCodeを追加する。
Login時
var identityToken = Encoding.UTF8.GetString(appleIdCredential.IdentityToken); var authorizationCode = Encoding.UTF8.GetString(appleIdCredential.AuthorizationCode); var firebaseCredential = OAuthProvider.GetCredential( "apple.com", identityToken, rawNonce, authorizationCode); this.firebaseAuth.SignInWithCredentialAsync(firebaseCredential) .ContinueWithOnMainThread(task => HandleSignInWithUser(task, firebaseAuthCallback));
QuickLogin時
var rawNonce = GenerateRandomString(32); var nonce = GenerateSHA256NonceFromRawNonce(rawNonce); var quickLoginArgs = new AppleAuthQuickLoginArgs(nonce); this.appleAuthManager.QuickLogin( quickLoginArgs, credential => {
apple-signin-unity公式:https://github.com/lupidan/apple-signin-unity/wiki/Sign-in-with-Apple-Unity-Plugin:-Working-with-Firebase
参考:https://qiita.com/magosys/items/161a48ee00b6e3b00755
Exceptionで、SHA256 hash of the raw nonceのエラーが出るとき
エラー例
"" does not match the SHA256 hash of the raw nonce "" in the request.)
対応方法 nonceが正しいか確認する。