Giter Site home page Giter Site logo

Comments (5)

agentphantom avatar agentphantom commented on May 18, 2024 1

The problem happens only with Facebook -> Google.

The Google login provider will always take precedence over the Facebook one, here's an example:

Let's say my email address for Facebook and Google is the same: [email protected]

  1. If I login with Firebase using my Facebook account it will register with my email address, but it won't be trusted.

  2. If I then login with my Google account, the Facebook data will be overwritten with the Google one and the email address will become trusted.

  3. At this step I can't login anymore with Facebook, I will need to login with Google or it won't work at all (the Facebook login doesn't return the refreshToken anymore).

In this case you will have to tell the user that they can't login with Facebook anymore and they should use Google instead.

from firebase-as3.

sfxworks avatar sfxworks commented on May 18, 2024

So allowing the user to login from multiple providers would fix this option?

from firebase-as3.

rl-pavel avatar rl-pavel commented on May 18, 2024

Found a hack. Not 100% sure if this is a good idea, but it works.
Basically, if you log in with Facebook after you've used Google, Firebase will return errorCodeEmailAlreadyInUse error, so all we have to do is check if the error is of that type and just log the user in with Google.

FIRAuth.auth()?.signIn(with: FIRCredentials, completion: { (user, error) in
  if let errorCode = error?._code,
    let authError = FIRAuthErrorCode(rawValue: errorCode) {
    switch authError {
    case .errorCodeEmailAlreadyInUse:
      GIDSignIn.sharedInstance().signIn()
    default: self.showError(withMessage: "Couldn't sign in with Facebook")
    }
  }
})

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

Nice find!

Tonight I will give it another shot at this issue and document my results.

from firebase-as3.

agentphantom avatar agentphantom commented on May 18, 2024

I tried the following:

I had already my account with Gmail and logged in with Facebook, the login was successful and this was the response:

{
    "kind": "identitytoolkit#VerifyAssertionResponse",
    "federatedId": "http://facebook.com/1127852910645790",
    "providerId": "facebook.com",
    "localId": "QcGrHghblIg4T2qLWP0RVJL8AQf2",
    "emailVerified": false,
    "email": "[email protected]",
    "oauthAccessToken": "<Medium sized string>",
    "oauthExpireIn": 5183999,
    "firstName": "John",
    "lastName": "Smith",
    "fullName": "John Smith",
    "displayName": "John Smith",
    "idToken": "<Long String>",
    "timeZone": "-6",
    "photoUrl": "https://scontent.xx.fbcdn.net/v/t1.0-1/p100x100/418143_223575787734578_1621690654_n.jpg?oh=25b36d4a93ebcede1245e2944b188130&oe=596B6757",
    "context": "",
    "verifiedProvider": [
        "google.com"
    ],
    "needConfirmation": true,
    "rawUserInfo": "{my Facebook profile information as sent from the Graph API}"
}

The important things to notice are:

  • There's not a refreshToken in the response, which is the key for doing anything with auth in Firebase.
  • emailVerified is set to false. This value is set to true when I log in with Google.
  • needConfirmation parameter which only appears when I try the previous sequence of actions.

My guess is that the Swift API already knows about this and gives you this particular error. In my case I will need to manually detect if the refreshToken exists and if not, redirect the user to the Google Auth.

from firebase-as3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.