问题
I've been struggling with his for quite some time now.. I have an app and also a Share Extension
.
Inside the Share Extension
the user needs to be authenticated so he can make requests to my Cloud-Firestore
(I set up the security rules so only authorized user can access data). However I am not able to authenticate the user inside my Share Extension
.
I already checked out Firebase Documentation and this SO-Question but that didn't help me.
In my case the user can sign in with Email, Google, Facebook & Apple.
I tried calling this inside App-Delegate didFinishLaunchingWithOptions
and in my ShareExtension
inside viewDidLoad
right after I call Firebase.configure()
:
do {
try Auth.auth().useUserAccessGroup(UserDefaults.Keys.accessGroupKey)
} catch let error as NSError {
print("Error changing user access group: %@", error)
}
But when trying to call Auth.auth.currentUser!
inside my ShareExtension
it always fails with a nil-error
.
Update:
When calling the code above on a clean simulator device it fails with this error
:
Error changing user access group: %@ Error Domain=FIRAuthErrorDomain Code=17995 "An error occurred when accessing the keychain. The @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo dictionary will contain more information about the error encountered" UserInfo={FIRAuthErrorUserInfoNameKey=ERROR_KEYCHAIN_ERROR, NSLocalizedFailureReason=SecItemCopyMatching (-34018), NSLocalizedDescription=An error occurred when accessing the keychain. The @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo dictionary will contain more information about the error encountered}
In Signing & Capabilities I have enabled App-Groups for both app and extension with the same identifier.
Same goes for Keychain-Sharing. The identifier I am using there is the same as UserDefautls.Keys.accessGroupKey
from the code above.
I am really struggling with this topic and I couldnt find a Step-by-step guide that is working for me. I feel like I am missing something, only calling the code above is not doing anything for me. If anyone can help me out here I am more then grateful!
If anything is unclear or you need more info just let me know!
来源:https://stackoverflow.com/questions/64668523/authenticate-user-in-share-extension-with-firebase