Skip to content

Implement Sign In with Google

Ben Myers edited this page Apr 22, 2022 · 3 revisions

Thanks for choosing EasyFirebase! πŸŽ‰ Follow these steps to implement Google Sign-In into your iOS or macOS project.

Requisites

Set Up Your Project

Go to your Google Cloud Console, and navigate to APIs & Services. Click the Credentials tab, then click Create Credential. In the drop-down, choose OAuth Client ID.

Create OAuth Client ID

iOS

In the Application Type drop-down, choose iOS. Next, fill in the fields. For Name, choose any name relating to Google Sign-In. For Bundle ID, use your Xcode project bundle ID. You can leave the remaining fields blank, and click Create.

You'll then get an important pop-up. ⚠️ Click Download plist. This contains your Client ID, which you'll use to sign in with Google.

macOS

In the Application Type drop-down, choose Desktop. Next, fill in the Name field with any name relating to Google Sign-In. Then click Create.

You'll then get an important pop-up. ⚠️ Click Download plist. This contains your Client ID and Client Secret, which you'll use to sign in with Google.

Add Google Sign-In to Firebase Auth

Go to your Firebase Console. Select the Authentication tab, then Sign-in Method. Click Add new provider, then choose Google.

Toggle the Enable switch, then fill out the appropriate fields. Finally, click Save.

Implement Google Sign-In in Your Project

iOS

Copy your Client ID that you saved from earlier. Remove .apps.googleusercontent.com from the end:

Before: xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
After:  xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

In your view, create a Google Sign-In button, that, when pressed, executes the following:

EasyAuth.signInWithGoogle(clientID: "xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") { error in
  // If error is not-nil, an issue occurred.
}

macOS

Copy your Client ID and Secret that you saved from earlier. Remove .apps.googleusercontent.com from the end of the Client ID:

Client ID Before: xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com
Client ID After:  xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Client Secret: GOCSPX-xxxxxxxxxxxxxxxxxxxxxxxxxxxx

In your view, create a Google Sign-In button, that, when pressed, executes the following:

EasyAuth.signInWithGoogle(clientID: "xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                          secret: "GOCSPX-xxxxxxxxxxxxxxxxxxxxxxxxxxxx") { error in
  // If error is not-nil, an issue occurred.
}