Google Sign-In for iOS and macOS

repository·main·Indexed 20 days ago

https://github.com/google/googlesignin-ios

A library providing secure authentication for native iOS and macOS applications using Google accounts. Includes support for SwiftUI via GoogleSignInButton, UIKit via GIDSignInButton, and AppKit via NSHostingView. Documentation covers installation via CocoaPods and Swift Package Manager, Keychain Access Group configuration for macOS and Mac Catalyst, and implementation details for various UI frameworks.

Tokens
2K
Snippets
12
Records
16
Agent score
73%

What's inside googlesignin-ios

  1. Get Started with Google Sign-In Samples

    main

    You can explore the implementation details by running the provided sample projects. There are samples available for both Objective-C and Swift.

    To run the Objective-C sample using CocoaPods:

    1. Clone the repository.
    2. Navigate to the Objective-C sample directory.
    3. Run pod install.
    4. Open the generated .xcworkspace file.

    To run the Objective-C sample using Swift Package Manager:

    1. Clone the repository.
    2. Open the .xcodeproj file directly in Xcode.

    For a Swift-specific example, refer to the DaysUntilBirthday sample.

    # Using CocoaPods
    git clone https://github.com/google/GoogleSignIn-iOS
    cd GoogleSignIn-iOS/Samples/ObjC/SignInSample/
    pod install
    open SignInSampleForPod.xcworkspace
    
    # Using Swift Package Manager
    git clone https://github.com/google/GoogleSignIn-iOS
    open GoogleSignIn-iOS/Samples/ObjC/SignInSample/SignInSample.xcodeproj
  2. Manage App Check secrets and API keys

    main

    The sample app requires a web API key and a debug token (used for local simulator testing via AppCheckCore).

    Local Development

    Secrets can be managed using an .xcconfig file. The project uses a placeholder file located at Secrets/AppCheckDefaultSecrets.xcconfig. You can add your API key to this file, but ensure it is not committed to your repository.

    Continuous Integration (CI)

    In CI environments, AppCheckSecretReader.swift is used to retrieve secrets from environment variables. You should provide these values to your xcodebuild command.

  3. Install the sample app via CocoaPods

    main

    To set up the DaysUntilBirthday sample app using CocoaPods, navigate to the ../Samples/Swift/DaysUntilBirthday/ directory, install the dependencies, and open the workspace.

    1. Run pod install.
    2. Open DaysUntilBirthdayForPod.xcworkspace.
    3. Run either the DaysUntilBirthdayForPod (iOS) or DaysUntilBirthdayForPod (macOS) target.
    pod install
    open DaysUntilBirthdayForPod.xcworkspace
  4. Configure Keychain Access Groups for macOS and Mac Catalyst

    main

    When building for macOS or using Mac Catalyst, you must configure Keychain Access Groups to ensure credentials can be stored correctly.

    Requirements:

    • Add $(AppIdentifierPrefix)$(CFBundleIdentifier) as the first item in your app's keychain access group.

    Important Note on Credential Removal: Google Sign-In removes keychain items upon a fresh install to prevent stale credentials from being used. If you use a shared access group, a new install might accidentally remove credentials for other apps sharing that group. To prevent this, explicitly list your app's specific default access group (e.g., $(AppIdentifierPrefix)$(CFBundleIdentifier)) as the first item in your list.

  5. Run integration tests with credentials

    main

    The integration tests for the DaysUntilBirthday(iOS) sample app require a Google account (email and password) to attempt a login.

    Via Xcode

    1. Select Edit Scheme > Run > Environment Variables.
    2. Add EMAIL_SECRET and PASSWORD_SECRET with your test account credentials.
    3. Alternatively, you can edit Credential.swift directly (but do not check these credentials into version control).

    Via Command Line

    Pass the credentials as environment variables to the xcodebuild command:

    xcodebuild <other args> EMAIL_SECRET=... PASSWORD_SECRET=...