GoogleSignIn-iOS icon indicating copy to clipboard operation
GoogleSignIn-iOS copied to clipboard

Support for Vision OS

Open AhsanAli65 opened this issue 1 year ago • 19 comments

Support needed for Vision OS in order to build Vision pro Apps

AhsanAli65 avatar Dec 01 '23 10:12 AhsanAli65

Yeah I get the error

Receiver 'OIDAuthState' for class message is a forward declaration

WillBishop avatar Dec 24 '23 04:12 WillBishop

Same here, need support.

kevinmore avatar Jan 06 '24 17:01 kevinmore

So, after almost a day's digging, I've managed to make it working in visionOS. Basically, we need to let the signin assume that visionOS is MacCatalyst.

You'll need to checkout and modify AppAuth-iOS, GTMAppAuth and GoogleSignIn-iOS individually.

Sorry guys, I can't share detailed steps, let's wait for an official release.

Screenshot 2024-01-07 at 15 18 15

kevinmore avatar Jan 07 '24 15:01 kevinmore

This library works for "Built for iPad" apps, which are similar to mac catalyst but for visionOS. I managed to get it working and get the same visionos-native looking interface as kevinmore. This shows that it does have the ability to work on visionos.

However, there doesn't seem to be a way to have it work on visionos-native apps. The dependencies of this library are also built specifically for iOS and macOS, and their #if TARGET_OS_(something) were seemingly built with the assumptions that there wouldn't be anything outside of iOS and macOS running their libraries. There are several statements like

#if TARGET_OS_IOS
// something here
#elseif TARGET_OS_OSX
// something else here
#endif

all throughout this library and its dependencies. Usually, one of the two cases would be true. However, when compiling for visionos native targets, neither of these conditions are true, leading to many syntax errors.

This means that this issue can't be solved unless a) Somebody figures out how to embed built-for-ipad libraries within a VisionOS native app. Given that embedding mac catalyst components within a native mac app is unheard of, I don't think this is possible. I might be wrong though. b) The dependencies ALL support VisionOS, which will take a long time and at least some coordinated effort.

KaiTheRedNinja avatar Jan 16 '24 14:01 KaiTheRedNinja

@KaiTheRedNinja Nope, I'm building a native visionOS app, not a compatible iPad app, with Firebase as backend. And I can confirm Google Sign In works. I'm not targeting other platforms than visionOS, so I just replaced Mac Catalyst targets with visionOS. For a full support of all platforms, let's wait for the official release.

kevinmore avatar Jan 16 '24 14:01 kevinmore

Hi everybody. We are investigating this and will hopefully update this thread in a bit with our plan.

mdmathias avatar Jan 17 '24 20:01 mdmathias

Thanks for looking into this!

SAllen0400 avatar Jan 22 '24 13:01 SAllen0400

Any update?

exentrich avatar Feb 16 '24 11:02 exentrich

Unfortunately no. Thanks for checking. We will update here when we do have anything to share.

mdmathias avatar Feb 16 '24 17:02 mdmathias

@mdmathias I'm eagerly anticipating this as well. However, it's unfortunate that Google didn't anticipate the need for an updated version during the beta phase of visionOS. This means we'll likely encounter bugs that need addressing, making the initial release feel more like just a beta version. As a result, stability might still be an issue even with the upcoming release, at least in my estimation. It's surprising that such foresight wasn't part of the planning process. Incorporating measures to address potential issues during the beta phase could have been a proactive approach to ensuring a smoother transition to the final release. It's crucial to anticipate and mitigate challenges early on to deliver a more stable and polished product to users.

Volodymyr-13 avatar Mar 04 '24 13:03 Volodymyr-13

Hi @Volodymyr-13. We do our best to keep up with everything we can amidst our many responsibilities. I would like to mention that this repository is open source and we welcome contributions from the community. Regardless, I apologize for any difficulty you're experiencing related to the absence of visionOS support in GSI.

mdmathias avatar Mar 04 '24 19:03 mdmathias

My solution was to remove the Google sign-in from my App and leave only the AppleID sign-in. Google won't pay me to contribute to their library and eventually they are the ones who lose

herberthobregon avatar Mar 04 '24 19:03 herberthobregon

I would like to mention that this repository is open source and we welcome contributions from the community.

I find it quite disheartening and AWKWARD to hear that a company as renowned as great GOOGLE relies on volunteer support for its official product repository. It seems totally unexpected and absolutely disappointing, considering Google's stature in the industry. This situation raises questions about the company's approach to supporting its own products. While I understand you're just doing your job here and I'm not directing this frustration at you personally, but I hope this feedback reaches someone higher up who can address it. However... less likely, I'm I right?

Volodymyr-13 avatar Mar 04 '24 20:03 Volodymyr-13

I would like to mention that this repository is open source and we welcome contributions from the community.

I find it quite disheartening and AWKWARD to hear that a company as renowned as great GOOGLE relies on volunteer support for its official product repository.

It seems totally unexpected and absolutely disappointing, considering Google's stature in the industry.

This situation raises questions about the company's approach to supporting its own products.

While I understand you're just doing your job here and I'm not directing this frustration at you personally, but I hope this feedback reaches someone higher up who can address it. However... less likely, I'm I right?

I've learned this the hard way within the OSS community, even sub-sections ran by corporations like Google. That sometimes you kind of have to go ahead and start DiY-ing the solutions yourself. It's what I'll be doing myself, as I have a currently ongoing project that requires the use of retrieving JWT tokens from a Google Sign In.

I get it sucks, but that's really the life of a software developer. Nobody said this was easy. 😉

Also for the record, if Google doesn't release their implementation before I go ahead and solve it myself, I'll make a PR with the added in implementation and will link it here.

MarcoDotIO avatar Mar 04 '24 20:03 MarcoDotIO

For everyone else who eagerly wants this, I found moving away from this SDK really not that hard. Took me about 1.5-2 hours to figure it all out, but with about 100 lines of code I've got Google Sign In working without the SDK (and it works with Firebase).

For me the steps were:

  1. Registered a new client on the Google console
  2. Used ASWebAuthenticationSession
  3. Create a redirect on my website to a "myapp://" URL
  4. Exchange the code for an access token and ID token,
  5. Hand that off to Firebase :)

WillBishop avatar Mar 30 '24 06:03 WillBishop

For everyone else who eagerly wants this, I found moving away from this SDK really not that hard. Took me about 1.5-2 hours to figure it all out, but with about 100 lines of code I've got Google Sign In working without the SDK (and it works with Firebase).

For me the steps were:

  1. Registered a new client on the Google console
  2. Used ASWebAuthenticationSession
  3. Create a redirect on my website to a "myapp://" URL
  4. Exchange the code for an access token and ID token,
  5. Hand that off to Firebase :)

Can you provide some sample code on your end? For my setup, my visionOS app crashes on startup with a EXC_BAD_ACCESS error:

Screenshot 2024-03-30 at 11 50 58 AM

Here's also my content view:

import SwiftUI
import AuthenticationServices

struct ContentView: View {
    @State private var authenticationSession: ASWebAuthenticationSession?
    
    var body: some View {
        Button("Sign in with Google") {
            startGoogleSignIn()
        }
    }
    
    private func startGoogleSignIn() {
        let clientId = "YOUR_CLIENT_ID.apps.googleusercontent.com"
        let redirectUri = "YOUR_BUNDLE_ID:/oauth2redirect"
        let authUrl = URL(string: "https://accounts.google.com/o/oauth2/v2/auth?client_id=\(clientId)&redirect_uri=\(redirectUri)&response_type=code&scope=email")!
        let callbackUrlScheme = "YOUR_BUNDLE_ID"
        
        authenticationSession = ASWebAuthenticationSession(url: authUrl, callbackURLScheme: callbackUrlScheme) { callbackURL, error in
            guard error == nil, let callbackURL = callbackURL else { return }
            
            let queryItems = URLComponents(string: callbackURL.absoluteString)?.queryItems
            if let code = queryItems?.first(where: { $0.name == "code" })?.value {
                // Use this authorization code to get an access token
                print("Authorization code: \(code)")
            }
        }
        
        authenticationSession?.presentationContextProvider = UIApplication.shared.windows.first?.rootViewController
        authenticationSession?.start()
    }
}

extension UIViewController: ASWebAuthenticationPresentationContextProviding {
    public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
        return self.view.window ?? ASPresentationAnchor()
    }
}

Edit: Seems like the state variable was causing the error. So after some rework, I'm getting this error:

Screenshot 2024-03-30 at 11 59 34 AM

Update 2: Just had to fix some stuff with the Build Identifier. I'll post a link to an example SwiftUI App here soon.

MarcoDotIO avatar Mar 30 '24 15:03 MarcoDotIO

Update 2: Just had to fix some stuff with the Build Identifier. I'll post a link to an example SwiftUI App here soon.

Hi @MarcoDotIO, would love the link to the example SwiftUI app if you have it, thank you!!

jparismorgan avatar Apr 12 '24 11:04 jparismorgan

Hi, I wrote an article regarding this issue. Hope it can help anyone who needs it! https://jevonlevin.medium.com/sign-in-with-google-on-your-swiftui-vision-pro-app-15d542b8dfd7

je-von avatar Apr 14 '24 10:04 je-von

I am still seeing this on 7.1.0 and having trouble upgrading to 8.0.0 on XCode. Has this been fixed? or do we need to continue using the workaround?

chriscycheng avatar Aug 29 '24 21:08 chriscycheng