google / GoogleSignIn-iOS

Enables iOS and macOS apps to sign in with Google.
https://developers.google.com/identity/sign-in/ios
Apache License 2.0
478 stars 194 forks source link

Support for Vision OS #353

Open AhsanAli65 opened 9 months ago

AhsanAli65 commented 9 months ago

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

WillBishop commented 8 months ago

Yeah I get the error

Receiver 'OIDAuthState' for class message is a forward declaration

kevinmore commented 8 months ago

Same here, need support.

kevinmore commented 8 months ago

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
KaiTheRedNinja commented 8 months ago

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.

kevinmore commented 8 months ago

@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.

mdmathias commented 7 months ago

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

SAllen0400 commented 7 months ago

Thanks for looking into this!

exentrich commented 6 months ago

Any update?

mdmathias commented 6 months ago

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

Volodymyr-13 commented 6 months ago

@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.

mdmathias commented 6 months ago

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.

herberthobregon commented 6 months ago

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

Volodymyr-13 commented 6 months ago

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?

MarcoDotIO commented 6 months ago

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.

WillBishop commented 5 months ago

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 :)
MarcoDotIO commented 5 months ago

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.

jparismorgan commented 5 months ago

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!!

je-von commented 5 months ago

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

chriscycheng commented 1 week ago

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?