Open navaronbracke opened 1 year ago
@navaronbracke Although I am no ios engineer I managed to fix up GoogleWrapper
file 😬
Can you try it out to see if it works for you?
google_sign_in: ^6.1.3
flutter_facebook_auth: ^5.0.11
// GoogleWrapper.swift
// GigyaSwift
//
// Created by Shmuel, Sagi on 15/04/2019.
// Copyright © 2019 Gigya. All rights reserved.
//
import UIKit
import GoogleSignIn
import Gigya
class GoogleWrapper: ProviderWrapperProtocol {
var clientID: String?
private lazy var googleLogin: GoogleInternalWrapper = {
return GoogleInternalWrapper()
}()
required init() {
}
func login(params: [String: Any]? = nil, viewController: UIViewController? = nil,
completion: @escaping (_ jsonData: [String: Any]?, _ error: String?) -> Void) {
googleLogin.login(params: params, viewController: viewController, completion: completion)
}
func logout() {
googleLogin.logout()
}
}
private class GoogleInternalWrapper: NSObject {
let defaultScopes = ["https://www.googleapis.com/auth/plus.login", "email"]
var clientID: String? = {
return Bundle.main.infoDictionary?["GoogleClientID"] as? String
}()
var googleServerClientID: String? {
return Bundle.main.infoDictionary?["GoogleServerClientID"] as? String
}
lazy var googleLogin: GIDSignIn = {
return GIDSignIn.sharedInstance
}()
func login(params: [String: Any]? = nil, viewController: UIViewController? = nil,
completion: @escaping (_ jsonData: [String: Any]?, _ error: String?) -> Void) {
guard let viewController = viewController, let clientID = clientID, let googleServerClientID = googleServerClientID else {
return
}
googleLogin.addScopes(defaultScopes, presenting: viewController)
googleLogin.signIn(with: GIDConfiguration(clientID: clientID, serverClientID: googleServerClientID), presenting: viewController) { user, error in
if let error = error {
completion(nil, error.localizedDescription)
return
}
if let user = user {
let jsonData = ["accessToken": user.serverAuthCode ?? ""]
completion(jsonData, nil)
}
}
}
func logout() {
googleLogin.signOut()
}
}
Hey @navaronbracke! 👋 Below you can find GoogleWrapper adjusted for latest GoogleSignIn version (GoogleSignIn 7).
import UIKit
import GoogleSignIn
import Gigya
class GoogleWrapper: ProviderWrapperProtocol {
let defaultScopes = ["https://www.googleapis.com/auth/plus.login", "email"]
var clientID: String? = {
return Bundle.main.infoDictionary?["GIDClientID"] as? String
}()
var googleServerClientID: String? {
return Bundle.main.infoDictionary?["GoogleServerClientID"] as? String
}
lazy var googleLogin: GIDSignIn = {
return GIDSignIn.sharedInstance
}()
required init() {
}
func login(params: [String: Any]? = nil, viewController: UIViewController? = nil,
completion: @escaping (_ jsonData: [String: Any]?, _ error: String?) -> Void) {
guard let viewController = viewController, let clientID = clientID, let serverClientID = googleServerClientID else {
print("Missing value in Info.plist");
return
}
googleLogin.configuration = GIDConfiguration.init(clientID: clientID, serverClientID: serverClientID);
googleLogin.currentUser?.addScopes(defaultScopes, presenting: viewController);
googleLogin.signIn(withPresenting: viewController){ result, error in
if let error = error {
completion(nil, error.localizedDescription)
return
}
if let user = result?.user {
let jsonData = ["accessToken": result?.serverAuthCode ?? ""]
completion(jsonData, nil)
}
}
}
func logout() {
googleLogin.signOut()
}
}
All up-to-date ios wrappers can be found on ios gigya sdk repo. https://github.com/SAP/gigya-swift-sdk/releases/tag/1.6.3
Currently the Swift wrapper classes for Facebook & GoogleSignIn are out of date, which breaks the example app on iOS. You can run the example if you comment out the Swift wrappers, but that is not ideal for a fully featured example app.
Proposal
google_sign_in
&facebook_auth
dependencies (the versions are a bit out of date)