콘텐츠로 건너뛰기

Firebase Google Login on iOS

This guide will help you integrate Google Sign-In with Firebase Authentication on iOS. I assume you have already completed the general Firebase Google setup.

  1. Go to your project overview over at console.cloud.google.com

    Firebase Project Overview
  2. Click on the Add app button

    Firebase Add App Button Firebase Add App Button
  3. Select iOS

    Firebase Add App iOS Button
  4. Fill the first part of the form

    1. Fill the Apple bundle ID
      1. Open Xcode at your app using npx cap open ios
      2. Double click on App App target in Xcode project navigator
      3. Ensure that you are on Targets -> App Targets section in Xcode with App selected
      4. Find your Bundle Identifier Bundle Identifier field in Xcode project settings
      5. Copy the Bundle Identifier and paste it in the Firebase console Firebase Add App iOS Bundle ID Field
    2. Click on the Register app button Firebase Add App iOS Register Button
  5. Skip the Download config file step

    Firebase Add App iOS Skip Download Button
  6. Skip the Add firebase SDK step

    Firebase Add App iOS Skip Download Firebase SDK Button
  7. Skip the Add initialization code step

    Firebase Add App iOS Skip Add Initialization Code Button
  8. Click on the Continue to console button

    Firebase Add App iOS Continue to Console Button
  9. Get your iOS client ID and your YOUR_DOT_REVERSED_IOS_CLIENT_ID

    1. Go to Google Cloud Console at console.cloud.google.com

    2. Find your project

      1. Click on the project selector Google Cloud Console Project Selector
      2. Search up your project by the exact name of your Firebase project and click on it. In my case, it is sociallogin-tutorial-app. Firebase Project Selector Project
    3. Open the search bar and open credentials

      1. Open the search bar Google Cloud Console Search Bar
      2. Search for credentials and click on the APIs and Services one (number 2 on the screenshot) Google Cloud Console Credentials Search
    4. Click on the iOS client for [YOUR_APP_ID] (auto created by Google Service) one. In my case, it is sociallogin-tutorial-app.

      Google Cloud Console Credentials iOS Client ID
    5. Copy the Client ID as well as the iOS URL scheme. This will be respectively your iOSClientId and YOUR_DOT_REVERSED_IOS_CLIENT_ID.

      Google Cloud Console Credentials iOS Client ID Copy
  10. Get your web client ID

    1. Go back to the Firebase console and go to Build -> Authentication Firebase Authentication Menu
    2. Click on the Sign-in method button Firebase Authentication Sign-in Method Button
    3. Click on the Google provider Firebase Authentication Sign-in Method Google Provider
    4. Click on the Web SDK configuration button Firebase Authentication Sign-in Method Web SDK Configuration Button
    5. Copy the Web client ID. This will be your webClientId in the initialize method of the plugin. Firebase Authentication Sign-in Method Web SDK Configuration Web Client ID
  11. Modify your app’s Info.plist

    1. Open Xcode and find the Info.plist file

      Info.plist file in Xcode project navigator
    2. Right click this file and open it as source code

      Right-click menu showing Open As Source Code option
    3. At the bottom of your Plist file, you will see a </dict> tag

      Closing dict tag in Info.plist file
    4. Insert the following fragment just before the closing </dict> tag

      Info.plist with URL schemes code inserted before closing dict tag
      <key>CFBundleURLTypes</key>
      <array>
      <dict>
      <key>CFBundleURLSchemes</key>
      <array>
      <string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
      </array>
      </dict>
      </array>
      <key>GIDClientID</key>
      <string>YOUR_IOS_CLIENT_ID.apps.googleusercontent.com</string>
    5. Change the YOUR_DOT_REVERSED_IOS_CLIENT_ID to the value copied in step 9 (the iOS URL scheme)

      Info.plist with actual reversed client ID inserted in URL schemes
  12. Change the YOUR_IOS_CLIENT_ID to the iOS Client ID you copied in step 9

  13. Save the file with Command + S

  14. Modify the AppDelegate.swift

    1. Open the AppDelegate

      AppDelegate.swift file in Xcode project navigator
    2. Insert import GoogleSignIn at the top of the file

      AppDelegate.swift with GoogleSignIn import added
    3. Find the func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) function

      Original application openURL function in AppDelegate
    4. Modify the function to look like this

      func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
      // Called when the app was launched with a url. Feel free to add additional processing here,
      // but if you want the App API to support tracking app url opens, make sure to keep this call
      var handled: Bool
      handled = GIDSignIn.sharedInstance.handle(url)
      if handled {
      return true
      }
      return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
      }
      Modified application openURL function with GoogleSignIn handling
    5. Save the file with Command + S

  15. Using the Google login in your app

    At this step, you are ready to use the Google login in your app. Please use the authUtils.ts file of the example app to authenticate with Google.

The user will be automatically created in Firebase Auth on first sign-in

If authentication hangs or fails:

  • Verify the idToken audience matches your Firebase web client ID
  • Check that Google Sign-In is enabled in Firebase Console
  • Ensure Info.plist has the correct URL schemes and GIDClientID
  • Verify iOSServerClientId matches your web client ID
  • Review the example app code for reference