Before you can begin integrating your iOS or macOS app with the Google Sign-In components,
you must download the dependencies and configure your Xcode project. The steps on
this page do just that. The [next steps](https://developers.google.com/identity/sign-in/ios/start-integrating#next_steps) then describe how to integrate
Google Sign-In features into your app.

## Before you begin

Install a current version of [Xcode](http://developer.apple.com/xcode/).

## Install the Google Sign-In dependencies in your project

### CocoaPods

1. If you don't already have CocoaPods installed, follow the steps in the
   CocoaPods [Getting Started](https://guides.cocoapods.org/using/getting-started.html)
   guide.

2. Open a terminal window and navigate to the location of your app's Xcode
   project.

3. If you have not already created a Podfile for your application, create one
   now:

   ```
   pod init
   ```

   <br />

4. Open the Podfile created for your application and add the following:

   ```
   pod 'GoogleSignIn'
   ```

   <br />

5. If you are using SwiftUI, also add the pod extension for the "Sign in
   with Google" button:

   ```
   pod 'GoogleSignInSwiftSupport'
   ```

   <br />

6. Save the file and run:

   ```
   pod install
   ```

   <br />

7. Open the generated `.xcworkspace` *workspace* file for your application in
   Xcode. Use this file for all future development on your application. (Note
   that this is different from the included `.xcodeproj` *project* file, which
   would result in build errors when opened.)

   You can refer to the [Objective-C sample app's
   Podfile](https://github.com/google/GoogleSignIn-iOS/blob/main/Samples/ObjC/SignInSample/Podfile)
   for an example.

### Swift Package Manager

1. Open your project in Xcode.

2. Add the Google Sign-In dependencies to your app
   ([Xcode documentation](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app)):

   |---|---|
   | **Repository** | `https://github.com/google/GoogleSignIn-iOS` |
   | **Version** | 9.0.0 |
   | **Package product** | GoogleSignIn |

3. If you are using SwiftUI, also add the following extension package product
   for the "Sign in with Google" button:

   |---|---|
   | **Package product** | GoogleSignInSwift |

## Get an OAuth client ID

Your app needs an OAuth client ID to identify itself to Google's authentication
backend. For iOS and macOS apps the [OAuth client ID application type](https://support.google.com/cloud/answer/6158849)
must be configured as iOS.

If you haven't already created an OAuth client ID, click the button
below to do so.

Create an OAuth client ID

After you create the OAuth client ID, take note of the client ID string, which
you will need to configure Google Sign-In in your app. You can optionally
download the configuration file, which contains your client ID and other
configuration data, for future reference.

If you already created an OAuth client ID, you can find your existing OAuth
information by clicking the button below.

[Get an existing OAuth client ID](https://console.developers.google.com/apis/credentials?project=_)

## Get an OAuth server client ID

Most apps will need to pass the identity of signed-in users to a backend service
of some kind. To securely pass the identity of users who signed in with Google
to your backend, you use ID tokens, as discussed in [Authenticate with a backend server](https://developers.google.com/identity/sign-in/ios/backend-auth).
Retrieving a user's ID token requires a second client ID---your *server*
client ID---which represents your backend.

To create a server client ID:

1. Open your project in the
   [Cloud console](https://console.developers.google.com/auth/clients).

2. Create a new **Web application** type OAuth client ID. Take note of the
   client ID string, which you will need to configure Google Sign-In in your
   app.

## Configure your application project

Google Sign-In requires your project to be configured with your OAuth client ID
and a custom URL scheme. Optionally, you can also add your server client ID for
[backend authentication](https://developers.google.com/identity/sign-in/ios/backend-auth) or optimize your app for your Google
Workspace domain.

### Add your OAuth client ID and custom URL scheme

Update your app's `Info.plist` file to add your *OAuth
client ID* and a custom URL scheme based on the *reversed client ID*.

The reversed client ID is your client ID with the order of the dot-delimited
fields reversed. This is also shown under "*iOS URL scheme* " when [selecting an
existing iOS OAuth client in the Cloud
console](https://console.developers.google.com/auth/clients). For example:
`com.googleusercontent.apps.1234567890-abcdefg`

<br />

```
<key>GIDClientID</key>
<string>YOUR_IOS_CLIENT_ID</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
    </array>
  </dict>
</array>
```

<br />

### Optional: Configure backend authentication

If you need to get users' ID tokens for [backend authentication](https://developers.google.com/identity/sign-in/ios/backend-auth),
also set the `GIDServerClientID` key in your app's `Info.plist` file.

> [!NOTE]
> **Note:** This is the OAuth client ID for your backend project, not the ID for your iOS or macOS app. You need to [get an OAuth server client ID](https://developers.google.com/identity/sign-in/ios/start-integrating#server_client_id) and specify it here.

<br />

```
<key>GIDServerClientID</key>
<string>YOUR_SERVER_CLIENT_ID</string>
```

<br />

### Optional: Optimize for a Google Workspace domain or OpenID realm

Use the `GIDHostedDomain` parameter if you want to optimize the sign-in flow for
a Google Workspace domain.

<br />

```
<key>GIDHostedDomain</key>
<string>YOUR_HOSTED_DOMAIN</string>
```

<br />

Use the `GIDOpenIDRealm` parameter if you want to specify an OpenID realm.

<br />

```
<key>GIDOpenIDRealm</key>
<string>YOUR_OPENID_REALM</string>
```

<br />

## Signing your application

Your application must be signed with a certificate issued by Apple to run
natively on macOS and iOS devices in order to store credentials using Keychain.

For your macOS app to successfully store credentials using Keychain, you will
also need to add `$(AppIdentifierPrefix)$(CFBundleIdentifier)` to its keychain
access group.

## Next steps

Now that you've downloaded the project dependencies and configured your Xcode
project, you can add [Google Sign-In](https://developers.google.com/identity/sign-in/ios/sign-in) to your iOS app.