Skip to content
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

Firebase Authentication's error code seems to be broken after upgrading to 5.4.0 #2522

Closed
mono0926 opened this issue Mar 12, 2019 · 17 comments
Closed
Assignees
Milestone

Comments

@mono0926
Copy link

@mono0926 mono0926 commented Mar 12, 2019

Describe your environment

  • Xcode version: Version 10.1 (10B61, latest)
  • Firebase SDK version: 5.18.0 (latest)
  • Firebase Component: Auth (5.4.0, latest)

Describe the problem

My app's auth logic was broken after upgrading to Firebase Authentication 5.4.0, so I investigated that.
It seems that FIRAuthErrorCodeInternalError(17999) error started occurring for many requests.

Steps to reproduce:

This is one of the steps to reproduce the issue.

  1. Login with anonymous Firebase user: success.
  2. Tried to link the Firebase user to exiting linked Facebook account.

After that, FIRAuthErrorCodeCredentialAlreadyInUse(17025) should return, but after upgrading to Firebase Authentication 5.4.0, FIRAuthErrorCodeInternalError(17999)started returning.

import FirebaseAuth
import FBSDKLoginKit

let firUser = Auth.auth().currentUser!
FBSDKLoginManager().logIn(withReadPermissions: ["public_profile"], from: viewController) { (result, error) in
    let fbToken = result!.token!

    let credential = FacebookAuthProvider.credential(withAccessToken: fbToken.tokenString)

    firUser.linkAndRetrieveData(with: credential, completion: { (result, error) in
        // error code should be `FIRAuthErrorCodeCredentialAlreadyInUse(17025)`
        // error code is `FIRAuthErrorCodeInternalError(17999)` after upgrading to Firebase Authentication 5.4.0
    })
}

I suspect that #2405 is related? 🤔

@mono0926 mono0926 changed the title Firebase Authenticator seems to be broken after upgrading 5.4.0 Firebase Authentication seems to be broken after upgrading 5.4.0 Mar 12, 2019
@mono0926 mono0926 changed the title Firebase Authentication seems to be broken after upgrading 5.4.0 Firebase Authentication' error code seems to be broken after upgrading 5.4.0 Mar 12, 2019
@mono0926 mono0926 changed the title Firebase Authentication' error code seems to be broken after upgrading 5.4.0 Firebase Authentication's error code seems to be broken after upgrading 5.4.0 Mar 12, 2019
@mono0926 mono0926 changed the title Firebase Authentication's error code seems to be broken after upgrading 5.4.0 Firebase Authentication's error code seems to be broken after upgrading to 5.4.0 Mar 12, 2019
@ryanwilson
Copy link
Member

@ryanwilson ryanwilson commented Mar 12, 2019

@mono0926 thanks for the reply, @renkelvin or @Yue-Wang-Google can you please take a look?

@renkelvin
Copy link
Contributor

@renkelvin renkelvin commented Mar 12, 2019

@mono0926 Thanks for reporting! It's verified that the issue was introduced in #2405 and we're working on the fix. Thanks!

@Yue-Wang-Google
Copy link
Contributor

@Yue-Wang-Google Yue-Wang-Google commented Mar 12, 2019

@mono0926 could you please try #2530 and see if it works for you? It works for me.

@Yue-Wang-Google
Copy link
Contributor

@Yue-Wang-Google Yue-Wang-Google commented Mar 13, 2019

@mono0926 I'll close this bug for now as it works for me plus we're freezing the code tonight.
Feel free to comment below whether it resolves your problem or not.

@mono0926
Copy link
Author

@mono0926 mono0926 commented Mar 13, 2019

@Yue-Wang-Google

Thanks, I checked that, but the issue seems to be not fixed unfortunately, so I'd like you to reopen this issue.

I checked it by running the code which pasted here( #2522 (comment) ), and add breakpoints to the code you modified.

v5.4.0 + #2530

shortErrorMessage is MISSING_ID_TOKEN.

Screen Shot 2019-03-13 at 14 39 06

Screen Shot 2019-03-13 at 14 40 33

v5.3.1

shortErrorMessage should be FEDERATED_USER_ID_ALREADY_LINKED.

Screen Shot 2019-03-13 at 14 44 05

Screen Shot 2019-03-13 at 14 54 07


You tried to fix kFederatedUserIDAlreadyLinkedMessage specific problem at #2530, but It might be more global problem as I said 🤔

My app's auth logic was broken after upgrading to Firebase Authentication 5.4.0, so I investigated that.
It seems that FIRAuthErrorCodeInternalError(17999) error started occurring for many requests.

@Yue-Wang-Google
Copy link
Contributor

@Yue-Wang-Google Yue-Wang-Google commented Mar 13, 2019

Thanks for reporting. #2530 did fix the issue when the user is new. However for existing users it seems the new code did return an wrong error. I'm going to reopen the issue. For now you could comment out FIRVerifyAssertionRequest.m's L154 (which set body[kReturnIDPCredentialKey] to @YES) or simply revert to the old version, if you need an urgent fix. I'll fix the bug tomorrow.

@mono0926
Copy link
Author

@mono0926 mono0926 commented Mar 13, 2019

@Yue-Wang-Google

comment out FIRVerifyAssertionRequest.m's L154 (which set body[kReturnIDPCredentialKey] to @yES)

This fixed the problem, thanks!!

image

@mono0926
Copy link
Author

@mono0926 mono0926 commented Mar 13, 2019

@Yue-Wang-Google

I believe I found the official fix: #2541

Oh, it should be fixed.

But, unfortunately without FIRVerifyAssertionRequest.m's L154 change, the problem isn't fixed.

1 revert the comment in FIRVerifyAssertionRequest.m's L154 (set it back to YES) if you commented it out. kReturnIDPCredentialKey needs to be true in order to make OAuth working.

Screen Shot 2019-03-13 at 16 44 23

2 You need to apply #2541

Screen Shot 2019-03-13 at 16 45 27

3 You also need to apply the previous fix #2530 --- both changes are necessary.

Screen Shot 2019-03-13 at 16 44 00

Result:

image

In summary, the results is below:

@mono0926
Copy link
Author

@mono0926 mono0926 commented Mar 13, 2019

I believe I found the official fix: #2541

Oh, it should be fixed.

I suspect that it was correct because initial implementation(May 16, 2017) used response.IDToken 🤔

accessToken:response.IDToken

Yue-Wang-Google added a commit that referenced this issue Mar 13, 2019
…ntial=YES

Fix #2522.

In this case, the server returns an 200 without an error like the following:

```
[response data:] {
  "error": {
    "code": 400,
    "message": "FEDERATED_USER_ID_ALREADY_LINKED",
    "errors": [
      {
        "message": "FEDERATED_USER_ID_ALREADY_LINKED",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}
```

Rather, it is directly enclosed in the response with an errorMessage without a structure:

```
 [response data:] {
  key: value
 ...
  "errorMessage": "FEDERATED_USER_ID_ALREADY_LINKED",
  "kind": "identitytoolkit#VerifyAssertionResponse"
}
```
@Yue-Wang-Google
Copy link
Contributor

@Yue-Wang-Google Yue-Wang-Google commented Mar 13, 2019

I'm very sorry. @mono0926 I must be drunk. Please try #2542 with #2530. (you need both patches, and you need to revert the kReturnIDPCredentialKey comment)
I'm very confident that this is the right fix.

Again, thank you for testing and reporting the bug to us! Really appreciated (next time I am in Tokyo I'll invite you for a beer)!

@mono0926
Copy link
Author

@mono0926 mono0926 commented Mar 13, 2019

Please try #2542 with #2530. (you need both patches, and you need to revert the kReturnIDPCredentialKey comment)

It works fine! Thanks for the quick fix 🙏

@Yue-Wang-Google
Copy link
Contributor

@Yue-Wang-Google Yue-Wang-Google commented Mar 13, 2019

It works fine! Thanks for the quick fix 🙏

Great! I'll wait for it to be approved by my colleague tomorrow, and after that v5.4.1 will be released.

Thanks for your bug report and testing my fixes. I will also keep my promise to buy you a beer, by the way:)

paulb777 added a commit that referenced this issue Mar 13, 2019
…2542)

* extract errorMessage directly from response in case of returnIDPCredential=YES

Fix #2522.

In this case, the server returns an 200 without an error like the following:

```
[response data:] {
  "error": {
    "code": 400,
    "message": "FEDERATED_USER_ID_ALREADY_LINKED",
    "errors": [
      {
        "message": "FEDERATED_USER_ID_ALREADY_LINKED",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}
```

Rather, it is directly enclosed in the response with an errorMessage without a structure:

```
 [response data:] {
  key: value
 ...
  "errorMessage": "FEDERATED_USER_ID_ALREADY_LINKED",
  "kind": "identitytoolkit#VerifyAssertionResponse"
}
```

* Update Changelog
@sentex
Copy link

@sentex sentex commented Mar 19, 2019

I have the same problem. Get FIRAuthErrorCodeInternalError(17999) after upgrading to Firebase Authentication 5.4.0

@Yue-Wang-Google
Copy link
Contributor

@Yue-Wang-Google Yue-Wang-Google commented Mar 19, 2019

@sentex
Copy link

@sentex sentex commented Mar 19, 2019

how can I install this version ?

@Yue-Wang-Google
Copy link
Contributor

@Yue-Wang-Google Yue-Wang-Google commented Mar 19, 2019

@sentex you can wait a day or two and see if it is upgraded on Cocoapods. Or, you can simply patch in #2542 and #2530.

@paulb777
Copy link
Member

@paulb777 paulb777 commented Mar 19, 2019

Or see instructions at https://github.com/firebase/firebase-ios-sdk#accessing-firebase-source-snapshots or wait an hour or so. We're publishing to CocoaPods now.

@firebase firebase locked and limited conversation to collaborators Oct 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.