Use Google Sign-In on macOS
mainsignInWithConfiguration: and addScopes: change slightly: they require a presentingWindow: parameter instead of a presentingViewController: parameter.repository·main·Indexed 20 days ago
https://github.com/google/googlesignin-iosA 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.
signInWithConfiguration: and addScopes: change slightly: they require a presentingWindow: parameter instead of a presentingViewController: parameter.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:
pod install..xcworkspace file.To run the Objective-C sample using Swift Package Manager:
.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.xcodeprojThe sample app requires a web API key and a debug token (used for local simulator testing via AppCheckCore).
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.
In CI environments, AppCheckSecretReader.swift is used to retrieve secrets from environment variables. You should provide these values to your xcodebuild command.
To set up the sample app using CocoaPods, navigate to the ../Samples/Swift/AppAttestExample/ directory, install the dependencies, and open the workspace.
```bash
cd ../Samples/Swift/AppAttestExample/
pod install
open AppAttestExample.xcworkspaceAfter opening the workspace, run the AppAttestExampleForPod target.
To set up the DaysUntilBirthday sample app using CocoaPods, navigate to the ../Samples/Swift/DaysUntilBirthday/ directory, install the dependencies, and open the workspace.
pod install.DaysUntilBirthdayForPod.xcworkspace.DaysUntilBirthdayForPod (iOS) or DaysUntilBirthdayForPod (macOS) target.pod install
open DaysUntilBirthdayForPod.xcworkspaceTo set up the DaysUntilBirthday sample app using Swift Package Manager, open the Xcode project directly.
DaysUntilBirthday.xcodeproj.DaysUntilBirthday (iOS) or DaysUntilBirthday (macOS) target.open DaysUntilBirthday.xcodeprojTo set up the Google Sign-In sample project using CocoaPods, navigate to the ../Samples/ObjC/SignInSample/ directory, install the required dependencies, and open the generated workspace.
cd ../Samples/ObjC/SignInSample/
pod install
open SignInSampleForPod.xcworkspaceApp Attest entitlement.When building for macOS or using Mac Catalyst, you must configure Keychain Access Groups to ensure credentials can be stored correctly.
Requirements:
$(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.
To set up the Google Sign-In sample project using Swift Package Manager, open the .xcodeproj file in the ../Sample/ObjC/SignInSample/ directory and run the 'SignInSample' target.
open ../Sample/ObjC/SignInSample/SignInSample.xcodeprojTo set up the sample app using Swift Package Manager, open the project file directly and run the primary target.
```bash
cd ../Samples/Swift/AppAttestExample/
open AppAttestExample.xcodeprojAfter opening the project, run the AppAttestExample target.
The integration tests for the DaysUntilBirthday(iOS) sample app require a Google account (email and password) to attempt a login.
EMAIL_SECRET and PASSWORD_SECRET with your test account credentials.Credential.swift directly (but do not check these credentials into version control).Pass the credentials as environment variables to the xcodebuild command:
xcodebuild <other args> EMAIL_SECRET=... PASSWORD_SECRET=...