class ViewModel : NSObject, ObservableObject, ASWebAuthenticationPresentationContextProviding {
private var authSession: ASWebAuthenticationSession?
func signInWithOpenID(provider: OAuthProvider) {
let url = getOIDCAuthenticationURL(provider: provider)
authSession?.cancel()
authSession = nil
authSession = ASWebAuthenticationSession(url: url, callbackURLScheme: "com.ninjanutri") { callbackURL, error in
if let error = error {
print("Error: \(error.localizedDescription)")
return
}
guard let callbackURL = callbackURL else { return }
guard let idToken = callbackURL.valueOf("id_token") else { return }
self.signInWithIdToken(provider: provider, idToken: idToken)
}
authSession?.prefersEphemeralWebBrowserSession = false
authSession?.presentationContextProvider = self
authSession?.start()
}
public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return ASPresentationAnchor()
}
}
struct ContentView: View {
@StateObject private var viewModel = ViewModel()
var body: some View {
Button {
viewModel.signInWithOpenID(provider: .github)
} label: {
Text("Test")
}
}
}
when the prefersEphemeralWebBrowserSession is false, the alert and webview is totally working fine in Simulator and Real device, but not XCode Preview
. Is this behaviour expected or it's a bug?