Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Technical Debt] Update Swift wrappers for Facebook & GoogleSignIn #59

Open
navaronbracke opened this issue May 17, 2023 · 3 comments
Open

Comments

@navaronbracke
Copy link
Contributor

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

  1. Bump the google_sign_in & facebook_auth dependencies (the versions are a bit out of date)
  2. Update the Swift wrappers for the integrations
@nemscep
Copy link
Contributor

nemscep commented Jun 5, 2023

@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()
    }
}

@nemscep
Copy link
Contributor

nemscep commented Dec 26, 2023

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()
    }
}

@nemscep
Copy link
Contributor

nemscep commented Jun 10, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants