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 official GoogleSignInSDK.
SDK can be installed using SPM. Just add following line into your Package.swift
:
.package(url: "https://github.com/AckeeCZ/OpenGoogleSignInSDK.git", .upToNextMajor(from: "1.0.0")),
or use the Xcode File -> Swift Packages -> Add Package Dependency
and paste the URL of GitHub repository.
🔜👀
Google Sign-In flow requires a URL scheme to be added to your project:
- Open your project configuration, select your app from the Targets section, then select the Info tab and expand the URL Types section.
- 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:
First, you need to visit Google API Console 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:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
OpenGoogleSignIn.shared.clientID = "YOUR_CLIENT_ID"
return true
}
In view controller which will present Google Sign-In flow, set the presentingViewController
property of OpenGoogleSignIn
shared instance inside viewDidLoad()
lifecycle method:
override func viewDidLoad() {
super.viewDidLoad()
OpenGoogleSignIn.shared.presentingViewController = self
}
To handle Sign-In process, you need to set OpenGoogleSignInDelegate
and implement the protocol:
OpenGoogleSignIn.shared.delegate = self
...
...
...
func sign(didSignInFor user: GoogleUser?, withError error: GoogleSignInError?) {
// Signed in user or error received here.
// Perform any required operations.
}
Ackee team
OpenGoogleSignInSDK is available under the MIT license. See the LICENSE file for more info.