Code: Select all
public func authenticate(completion: @escaping (String?) -> Void) {
let authURL = URL(string: "https://discord.com/api/oauth2/authorize?client_id=\(clientId)&redirect_uri=\(redirectUri)&response_type=code&scope=\(scopes)")!
print(authURL.absoluteString)
let session = ASWebAuthenticationSession.init(url: authURL, callback: .customScheme("infinitea"), completionHandler: { url, error in
if let url, let code = URLComponents(string: url.absoluteString)?.queryItems?.first(where: { $0.name == "code" })?.value {
completion(code)
return
} else {
completion(nil)
}
})
session.presentationContextProvider = self
session.start()
}
Code: Select all
identifier - com.mydomain.myproject
urlschemes - infinitea
< /code>
Schließlich habe ich diesen Code hinzugefügt, um die Umleitung der Post-Authentifizierung zu erfassen. var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(swiftCordAuth)
.onOpenURL { url in
print("Opening URL: \(url)")
self.swiftCordAuth.handleIncomingURL(url)
}
}
}