问题
So, I had everything working as of yesterday. Then I logged into my Firebase dashboard and there was a banner that suggested I try out the new Firebase console. "SURE! That sounds great" I thought.
Eight hours later, I cannot get Google Sign-In to work. Here is my GIDSignInDelegate method, which fires correctly and everything.
func signIn(signIn: GIDSignIn!,
didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
let authentication = user.authentication
let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,
accessToken: authentication.accessToken)
FIRAuth.auth()?.signInWithCredential(credential, completion: nil)
} else {
// Don't assert this error it is commonly returned as nil
print("\(error.localizedDescription)")
}
}
The problem seems to be that this doesnt create an event for
FIRAuth.auth()!.addAuthStateDidChangeListener
which is in my app delegate.
When logging in with the Facebook API, it does fire the auth state change listener.
I have also tried with a completion block, the user is a GIDGoogleUser instead of an FIRUser which seems kinda weird, but I have no proof it would be a problem. Also, the error is nil. so it looks like the signInWithCredential is working, but the auth state change listener isnt firing.
The only thing I can think of is that there is a problem with the google sign-in part of the system as the new GoogleService-Info.plist I had to download from the Firebase Console has a different app ID than I had in my previous GoogleService-Info.plist. I tried replacing the new app id with my old one which didn't work at all. I then tried removing any reference to the old app id assuming that the new one integrates google sign in automatically. Still no luck.
Anyone had success updating?
回答1:
What fixed this for me is to create a new Firebase Project.
Go to https://console.firebase.google.com and choose CREATE NEW PROJECT. I tried everything I could think of in my old (upgraded) project and I just couldn't make it work. Also adding a new iOS app inside the old project wasn't enough.
I understand this is a bad option for a production app but as I'm still in the development phase wasn't a big deal for me.
回答2:
I added "import FirebaseAuth" and it worked! I know the Firebase documentation didn't say to add this, but I decided to give it a try anyways.
回答3:
You need to add "Web SDK Configuration". You still need to enter it even though you may only have iOS app!
- Go to your "Auth" tab in the new Firebase console.
- Click on "Google" under "sign in providers"
- Hover over "Web SDK configuration (optional)", it will bring up the popover saying "Reuse a web client ID from an existing Google project. You can find your web client ID for existing projects by selecting your project and OAuth 2.0 entry on the Google API Console."
- Hit that link saying "Google API Console".
- Check under section "OAuth 2.0 client IDs". You need to click on the link "Web client (auto created by Google Service".
- Copy/Paste your "Client ID" and "Client Secret" into your Firebase console under section "Web SDK Configuration (optional)"
Funny thing that you need to do this even though you may have only iOS app.
Re-Run your xCode project.
来源:https://stackoverflow.com/questions/37336130/how-do-you-update-googlesign-in-to-work-with-the-new-firebase-console-and-apis