@react-native-google-signin/google-signin

repository·master·Indexed 25 days ago

https://github.com/react-native-google-signin/google-signin

A library providing Google authentication for React Native and Expo applications on Android and iOS. It includes the GoogleSignin class for managing authentication flows, a pre-built GoogleSigninButton UI component, and an Expo Config Plugin for automated native project configuration.

Tokens
3.5K
Snippets
6
Records
39
Agent score
85%

What's inside @react-native-google-signin/google-signin

  1. Compare Free vs Premium (Universal Sign In) implementation

    master

    The free version of @react-native-google-signin/google-signin supports Android and iOS using legacy SDKs.

    If you require modern Google identity APIs, cross-platform support (Web, macOS), or advanced configuration tools, use Universal Sign In.

    Universal Sign In features include:

    • Cross-platform support: Android (Credential Manager), iOS, web, and macOS.
    • Config Doctor: A CLI tool to diagnose Android configuration issues (e.g., DEVELOPER_ERROR).
    • Auto-detect: Automatic configuration parameter detection.
    • Advanced security: Custom nonce support and iOS App Check.
  2. Setup the Example App

    master

    To set up the example project, follow these steps:

    1. Install Javascript dependencies: Run yarn in the project root.
    2. Install iOS native dependencies: Navigate to example/ios/ and run pod install.
    3. Configure Google configuration files:
      • Place google-services.json in android/app/ (Note: for this specific example app, it resides in node_modules/react-native-test-app/).
      • Place GoogleService-Info.plist in node_modules/react-native-test-app/ios/ReactTestApp and link it in Xcode by dragging it into the file tree.
    4. Create a configuration file at src/confgi/config.js with your webClientId.
    export default {
      webClientId: 'your-web-client-id.apps.googleusercontent.com',
    };
  3. Use the Expo Config Plugin for automatic configuration

    master
    The @react-native-google-signin/google-signin package provides an Expo Config Plugin to automatically configure native project files (such as Android and iOS settings) when using Expo Prebuild or Continuous Native Generation (CNG). You can include this plugin in your app.json or app.config.js to automate the setup process.
  4. Configure Google Sign-In for Expo projects without Firebase

    master

    If you are not using Firebase, you must provide the iosUrlScheme option to the plugin. This option is required to configure the iOS URL scheme so that Google Sign-In can handle the redirect back to your app.

    Requirements for iosUrlScheme:

    • It must start with the prefix com.googleusercontent.apps..
    • It is typically found in your GoogleService-Info.plist file under the REVERSED_CLIENT_ID key.
  5. Configure Google Sign-In with ConfigureParams

    master

    Use ConfigureParams to initialize the Google Sign-In library. This configuration defines the scopes, client IDs, and access modes for your application.

    Key configuration options:

    • scopes: Array of Google API scopes to request (defaults to email and profile).
    • webClientId: Required for offline access to allow your server to exchange an authorization code for a refresh token.
    • offlineAccess: Set to true if you need to access user APIs from your own server.
    • hostedDomain: Restricts authorization to a specific domain.
    • iosClientId: (iOS only) The iOS client ID.
    • googleServicePlistPath: (iOS only) Custom path to your GoogleService-Info.plist file.

    Android Specifics:

    • forceCodeForRefreshToken: Use true only if your server has lost the user's refresh token.
    • accountName: An account name to prioritize.

    iOS Specifics:

    • openIdRealm: The OpenID2 realm of the home web server.
    • profileImageSize: Desired height/width for the profile image (defaults to 120px).
  6. Configure Expo support for @react-native-google-signin/google-signin

    master
    The @react-native-google-signin/google-signin package includes an Expo module configuration that enables integration with Expo projects. On iOS, it automatically registers GoogleSignInAppDelegate as an appDelegateSubscriber to handle Google Sign-In events within the app delegate lifecycle. It uses the podspec located at expo/ios/ExpoAdapterGoogleSignIn.podspec for CocoaPods integration.