|
1 | | -# OpenGoogleSignInSDK |
| 1 | +# OpenGoogleSignInSDK |
| 2 | + |
| 3 | +OpenGoogleSignInSDK is an open-source library which takes care of Google Sign-In flow using OAuth 2.0 and can be used as an alternative to GoogleSignIn SDK. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +### Swift Package Manager |
| 8 | + |
| 9 | +SDK can be installed using [SPM](https://github.com/apple/swift-package-manager). Just add following line into your `Package.swift`: |
| 10 | + |
| 11 | +```swift |
| 12 | +.package(url: "https://github.com/AckeeCZ/OpenGoogleSignInSDK.git", .upToNextMajor(from: "1.0.0")), |
| 13 | +``` |
| 14 | + |
| 15 | +or use the Xcode `File -> Swift Packages -> Add Package Dependency` and paste the URL of GitHub repository. |
| 16 | + |
| 17 | +## Integration guide |
| 18 | + |
| 19 | +### Add a URL scheme to your project |
| 20 | + |
| 21 | +Google Sign-In flow requires a URL scheme to be added to your project: |
| 22 | + |
| 23 | +1. Open your project configuration, select your app from the **Targets** section, then select the **Info** tab and expand the **URL Types** section. |
| 24 | +2. Click the **+** button, and add your reversed client ID as a URL scheme. The reversed client ID is your client ID with the order of the dot-delimited fields reversed, like on the picture below: |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +### Set OAuth 2.0 client ID |
| 29 | + |
| 30 | +First, you need to visit [Google API Console](https://console.developers.google.com/apis/credentials?project=_) to obtain OAuth 2.0 client ID of your project. After obtaining the client ID, you need to configure the `clientID` property of `OpenGoogleSignIn` shared instance in your app delegate: |
| 31 | + |
| 32 | +```swift |
| 33 | +func application(_ application: UIApplication, |
| 34 | + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { |
| 35 | + OpenGoogleSignIn.shared.clientID = "YOUR_CLIENT_ID" |
| 36 | + |
| 37 | + return true |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +### Handle Sign-In process |
| 42 | + |
| 43 | +To handle Sign-In process, you need to set `OpenGoogleSignInDelegate` and implement the protocol: |
| 44 | + |
| 45 | +```swift |
| 46 | +OpenGoogleSignIn.shared.delegate = self |
| 47 | + |
| 48 | +... |
| 49 | +... |
| 50 | +... |
| 51 | + |
| 52 | +func sign(didSignInFor user: GoogleUser?, withError error: GoogleSignInError?) { |
| 53 | + // Signed in user or error received here. |
| 54 | + // Perform any required operations. |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +## Author |
| 59 | + |
| 60 | +[Ackee](https://ackee.cz) team |
| 61 | + |
| 62 | +## License |
| 63 | + |
| 64 | +OpenGoogleSignInSDK is available under the MIT license. See the LICENSE file for more info. |
0 commit comments