I am using Firebase in my OS X application. I am trying to add Google Authentication. This is an example for iOS.
Question is: How to obtain Google OAuth access token in OS X application?
I am using Firebase in my OS X application. I am trying to add Google Authentication. This is an example for iOS.
Question is: How to obtain Google OAuth access token in OS X application?
UPDATED
Updated code for recent versions of Firebase. Signing in with Google (using OAuth) to authenticate with Firebase.
func someFunc {
let frameworkBundle = Bundle(for: GTMOAuth2WindowController.self)
let windowController = GTMOAuth2WindowController(scope: "https://www.googleapis.com/auth/plus.me", clientID: YOUR_CLIENT_ID, clientSecret: YOUR_CLIENT_SECRET, keychainItemName: "OAuth2 APP_NAME: Google+", resourceBundle: frameworkBundle)
guard let window = self.view.window else { return }
windowController?.signInSheetModal(for: window, delegate: self, finishedSelector: #selector(didFinishWithAuth(windowController:auth:error:)))
}
@objc func didFinishWithAuth(windowController:GTMOAuth2WindowController, auth: GTMOAuth2Authentication, error: NSError?) {
if error != nil {
print(error?.localizedDescription ?? String())
} else {
let credential = OAuthProvider.credential(withProviderID: GoogleAuthProviderID, accessToken: auth.accessToken)
Auth.auth().signIn(with: credential) { (auth, error) in
if let error = error {
print(error.localizedDescription)
return
}
// Successful sign in
}
}
}