Saturday, November 21, 2026
HomeiOS Developmentios - Swift Google Auth utilizing Firebase and extra scopes

ios – Swift Google Auth utilizing Firebase and extra scopes

[ad_1]

Utility makes use of GIDSignIn and Firebase for google authentication in my iOS app.

I’m attempting so as to add extra scopes to the authentication circulate, nonetheless, I have no idea the right approach so as to add the wanted scopes.

Google Register Documentation

func signInWithGoogle() {
        guard let clientID = FirebaseApp.app()?.choices.clientID else { return }

        // Create Google Signal In configuration object.
        let config = GIDConfiguration(clientID: clientID)
        
        

        // Begin the sign up circulate!
        GIDSignIn.sharedInstance.signIn(with: config, presenting: self) { [unowned self] person, error in

          if let error = error {
            // ...
            return
          }

          guard
            let authentication = person?.authentication,
            let idToken = authentication.idToken
          else {
            return
          }

          let credential = GoogleAuthProvider.credential(withIDToken: idToken,
                                                         accessToken: authentication.accessToken)
            

          // ...
            
            Auth.auth().signIn(with: credential, completion: { (person, error) in
                        if let err = error {
                            print("Didn't create a Firebase Person with Google account: ", err)
                            return
                        }
                        // Efficiently logged in
                        guard let uid = person?.person.uid else { return }
                        print("Efficiently logged into Firebase with Google", uid)
                        let mainTabBarController = TabBarViewController()
                        (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.changeRootViewController(mainTabBarController)

                    })
            
            
        }
    }

I want so as to add the code under so as to add scopes to the authentication course of. I simply dont know the best way to correctly ask for the scopes with out interrupting the firebase login course of.

let additionalScopes = ["https://www.googleapis.com/auth/youtube.readonly", "https://www.googleapis.com/auth/yt-analytics.readonly"]
        GIDSignIn.sharedInstance.addScopes(additionalScopes, presenting: self) { person, error in
            guard error == nil else { return }
            guard let person = person else { return }

            // Verify if the person granted entry to the scopes you requested.
            
        }

An analogous submit with the same drawback could be discovered right here

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments