I am trying to use the OAuth protocol to authenticate a user using the eBay API. I have created a separate class to handle the authenticatio with a function to start the process. I am calling the function from the login view via a button. When I click the button on the login screen nothing happens, not even an error.
class WebAuthenticate: NSObject, ObservableObject {
func authenticate() {
guard let authURL = URL(string: "https://auth.sandbox.ebay.com/oauth2/authorize")
else { return }
let scheme = "myapp"
//Initializing session
let session = ASWebAuthenticationSession(url: authURL, callbackURLScheme: scheme) {
callbackURL, error in
}
session.start()
}
}
extension WebAuthenticate: ASWebAuthenticationPresentationContextProviding {
func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
return ASPresentationAnchor()
}
}
Login View
import SwiftUI
struct LoginView: View {
@State var isAuthenticated = false
@StateObject private var auth = WebAuthenticate()
var body: some View {
VStack {
Text("Welcome, please login")
.padding(100)
Spacer()
if isAuthenticated {
VStack {
Text("You’re logged in!")
Button("Log out") {
logout()
}
} // VStack
} else {
VStack {
Button("Log in") {
auth.authenticate()
}
} // VStack
} // if isAuthenticated
} // Body Vstack
} // body
Would appreciate any help or reading material to figure this out.