-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sign in with Apple and anonymous users #4434
Comments
Hi @Sephiroth87, thanks for reporting this. I'll try to reproduce this behavior on my end, and I'll let you know with my findings. |
@Sephiroth87 I got the same behavior on my end. As what you have mentioned, it looks like the credential is only valid for a single request in Apple provider. Upon checking this link, the " It is also mentioned here that:
With this, it seems like you need to re-generate a random nonce string as this step is important to prevent replay attacks. |
Yes, the problem is, since the nonce is linked to the ID token, if I need to generate a new pair, I'd have to show the |
@Sephiroth87 Yes, you'd need to show the |
So basically "Sign in with Apple" and anonymous users are just incompatible? |
@renkelvin can you answer this last question? This sounds like it would be an issue for all nonce-related flows in the future, not just Apple. |
Try linking then sign in are actually 2 separate requests, so to be OIDC compliant, the nonce has to be different. And yeah, it's not just for Apple, it would be the same for other OAuth requests with nonce. |
Sounds like this is working as intended, though it's potentially confusing. |
@renkelvin I tried not setting the nonce, but I get the same error... |
Yeah, it seems Apple's credential is forbidden to reuse. Let me double check with my teammates. |
It's confirmed that you can't reuse the credential of Apple. The solution is that, once you receive the error after linking, you can retrieve an updated credential from the error object with: |
This is convoluted enough that we should probably document it. |
Thank you, it's working now 🎉 |
Docs updated at cr/288738567 (Googler-only link). They'll likely be merged and published at the end of this week or beginning of next. The automatic linking behavior is likely something we'll keep in FirebaseUI. |
The change has been submitted and should be reflected in the docs shortly. |
I am having the exact same problem, but error.userInfo only contains the error code and localized string, no value FIRAuthErrorUserInfoUpdatedCredentialKey, so I cannot use the trick mentioned by @renkelvin |
Can you share the error? If it's the same error, it's likely some weird provider behavior that requires a reauth under certain conditions. |
Error is ["FIRAuthErrorUserInfoNameKey": ERROR_MISSING_OR_INVALID_NONCE, "NSLocalizedDescription": Duplicate credential received. Please try again with a new credential.] |
Does this always happen, even with a very recent sign-in? |
Yes it does happen next time I try to sign in.
|
I am not a security engineer, but you should definitely get some expert advice before storing auth stuff in user defaults. In this case you're receiving the error because you're trying to re-use a nonce, and they exist specifically to avoid being re-used. |
Thanks @morganchen12 |
Firebase Auth will automatically persist your user in Keychain, so for normal user tasks you won't need to reauthenticate. For account-related tasks like linking a provider you will still need to reauthenticate. You should be able to fetch the uid without reauthenticating. |
OK, I get it now and it does work. |
No problem! |
Hi, we're having the issue with Unity and the Apple Sign In Popup coming up every time. We are on firebase 6.11 for Unity thnx |
Hey @simontgs, this thread has gotten a little out of hand. For Unity-related issues, please file a support ticket to Firebase Support. The user persistence is something that Auth does by default on iOS via Keychain, so it should work without requiring you to store any login information. Are you able to reproduce this bug in an iOS-only project? |
Hey morgan, thanks, we haven't tried a pure ios project only, we're just using Unity. We sign in with Apple Sign In ( Unity plugin ) - received the idToken from Apple and store that off We then use this in the following code. Note: first time in is fine, second time in, we pull the idToken out of our PlayerPrefs and feed it in and get the duplicate credential as a result.
Validate the token with firebase and sign in...
I'll fire an email to firebase support, thnx |
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
In our current setup, users are always logged in anonymously, then they can deicide to login/sign in, at which point we either link the anonymous user to the used provider or sign in.
This works fine with other providers (eg: Facebook), but using "Sign in with Apple", an existing user can't sign in, and I get the error:
Error Domain=FIRAuthErrorDomain Code=17094 "Duplicate credential received. Please try again with a new credential." UserInfo={NSLocalizedDescription=Duplicate credential received. Please try again with a new credential., FIRAuthErrorUserInfoNameKey=ERROR_MISSING_OR_INVALID_NONCE}
It seems that the credential is only valid for a single request, so I can't seem to be able to achieve this without having to show 2 login prompts, or discarding the anonymous user and simply using signIn
The text was updated successfully, but these errors were encountered: