// // ContentView.swift // GulliverTest // // Created by Bailey Townsend on 1/20/26. // import SwiftUI import Gulliver import Pulse import PulseProxy import PulseUI import AuthenticationServices struct ContentView: View { @State private var authSession: ASWebAuthenticationSession? @State private var contextProvider = AuthSessionContextProvider() var body: some View { NavigationStack{ VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") NavigationLink(destination: ConsoleView()) { Text("Console") } } } .task { do { #if DEBUG NetworkLogger.enableProxy() #endif let client = OAuthClient(clientId: "https://pace.social/oauth-client-metadata.json", redirectUri: "social.pace:/auth/callback") let url = try await client.createAuthorizationURL(identifier: "baileytownsend.dev") await MainActor.run { presentAuthSession(url: url) } } catch { print("Error creating authorization URL: \(error)") } } .padding() } private func presentAuthSession(url: URL) { // Create authentication session with callback URL scheme let session = ASWebAuthenticationSession( url: url, callbackURLScheme: "social.pace" ) { callbackURL, error in Task { print("Callback URL: \(String(describing: callbackURL)), Error: \(String(describing: error))") // await handleAuthCompletion(callbackURL: callbackURL, error: error) } } // Configure the session session.presentationContextProvider = contextProvider session.prefersEphemeralWebBrowserSession = false // Store and start the session authSession = session session.start() } } class AuthSessionContextProvider: NSObject, ASWebAuthenticationPresentationContextProviding { func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor { // Return the key window if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let window = windowScene.windows.first(where: { $0.isKeyWindow }) { return window } // Fallback: find any window scene and create a window if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene { if let window = windowScene.windows.first { return window } // Create a new window with the window scene return ASPresentationAnchor(windowScene: windowScene) } // Final fallback (should not reach here in normal circumstances) fatalError("No window scene available for authentication presentation") } } #Preview { ContentView() }