I would like to authenticate against an OAuth API usingASWebAuthenticationSession
however it doesn't seem to be usable from SwiftUI.
This is what I would like to have:
struct ContentView: View: ASWebAuthenticationPresentationContextProviding {
var body: some View {
NavigationView {
VStack {
Button("Hello World", {
// Run oauth flow
}
}
}
.navigationBarTitle(Text("Greed of Savin"))
.navigationViewStyle(StackNavigationViewStyle())
}
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return BungieApi.sharedInstance.presentationAnchor ?? ASPresentationAnchor()
}
}
}
It requires adopting the protocol ASWebAuthenticationPresentationContextProviding
which is not compatible with SwiftUI's Views.
I can get past this by redirecting to a ViewController that can then provides the ASWebAuthenticationPresentationContextProviding
, but that adds an additional view/navigation step.
Is there any way to use ASWebAuthenticationSession
from SwiftUI without dropping into a ViewController?