Something went wrong. Try again.
SwiftUI view testin Gulliver
Something went wrong. Try again.
3.2 kB · 101 lines · Created 8mo ago
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102//// ContentView.swift// GulliverTest//// Created by Bailey Townsend on 1/20/26.//
import SwiftUIimport Gulliverimport Pulseimport PulseProxyimport PulseUIimport 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()}