You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OAuth 5.3.2/ SwiftUI/ using macOS 13 run catalyst mode, will get this error:
2022-11-17 15:42:03.532115+0800 Crossword[1778:4730281] [TraitCollection] Class _UIFindNavigatorViewController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.
2022-11-17 15:42:20.836892+0800 Crossword[1778:4730281] [AXRuntimeCommon] Unknown client: Crossword
[Debug] OAuth2: Starting authorization
[Debug] OAuth2: No access token, checking if a refresh token is available
[Debug] OAuth2: Error refreshing token: I don't have a refresh token, not trying to refresh
[Debug] OAuth2: Opening authorize URL embedded: *****************HIDDEN*****************
[Debug] OAuth2: The operation couldn’t be completed. (com.apple.AuthenticationServices.WebAuthenticationSession error 2.)
Authorization was canceled or went wrong: The operation couldn’t be completed. (com.apple.AuthenticationServices.WebAuthenticationSession error 2.).
Both iOS/Mac are OK, only catalyst can not work :(
import OAuth2
#if os(iOS)
import UIKit
#elseif os(macOS)
import AppKit
#endif
import Combine
import WebKit
publicstructOAuth2Configuration{publicinit(clientId:String, authorizeUri:String, tokenUri:String, redirectUris:[String], scope:String, customParameters:OAuth2StringDict){self.clientId = clientId
self.authorizeUri = authorizeUri
self.tokenUri = tokenUri
self.redirectUris = redirectUris
self.scope = scope
self.customParameters = customParameters
}letclientId:StringletauthorizeUri:StringlettokenUri:StringletredirectUris:[String]letscope:StringletcustomParameters:OAuth2StringDictletlogLevel:OAuth2LogLevel=.debug
}publicclassOAuth2Coordinator:ObservableObject{// MARK: Stored Properties@PublishedvaraccessToken:String?publicprivate(set)vartext="Hello, World!"privatevaroauth2:OAuth2?privatevarcancellables=Set<AnyCancellable>()// MARK: Initializationpublicinit(configuration:OAuth2Configuration){letoauth2=OAuth2CodeGrant(settings:["client_id": configuration.clientId,"client_secret":"","authorize_uri": configuration.authorizeUri,"token_uri": configuration.tokenUri,"redirect_uris": configuration.redirectUris,"scope": configuration.scope,"parameters": configuration.customParameters,"secret_in_body": false,"keychain": true,"use_pkce": true,]asOAuth2JSON)
oauth2.logger =OAuth2DebugLogger(configuration.logLevel)
oauth2.afterAuthorizeOrFail ={[unowned self] authParameters, error inself.accessToken = oauth2.accessToken
}self.oauth2 = oauth2
}// MARK: Methodspublicfunc checkToken(){
if let hasUnexpiredAccessToken =self.oauth2?.hasUnexpiredAccessToken(), hasUnexpiredAccessToken {self.oauth2?.doRefreshToken(callback:{[unowned self] authParameters, error inself.accessToken =self.oauth2?.accessToken
})}}publicfunc setupWhenUIIsReady(){
if let oauth2 =self.oauth2 {#if os(iOS)letrootViewController=(UIApplication.shared.connectedScenes.first as?UIWindowScene)?.windows.first?.rootViewController
#elseif os(macOS)letrootViewController=NSApplication.shared.windows.first?.windowController
#endif
if rootViewController !=nil{
oauth2.authConfig.authorizeEmbedded = true
oauth2.authConfig.authorizeContext = rootViewController
oauth2.authConfig.ui.useSafariView = false
oauth2.authConfig.ui.useAuthenticationSession = true
oauth2.authConfig.ui.prefersEphemeralWebBrowserSession = true
}}}publicfunc authorize(){
if let oauth2 =self.oauth2 {
oauth2.authorize(){ authParameters, error in
if let error = error {print("Authorization was canceled or went wrong: \(error).")}}}}publicfunc unauthorize(){signOutTokenFromServer()removeCookies()self.oauth2?.abortAuthorization()self.oauth2?.forgetTokens()}privatefunc signOutTokenFromServer(){
if let oauth2 =self.oauth2 {
if let signOutUriString = oauth2.clientConfig.customParameters?.first(where:{ $0.key =="signOutUri"})?.value {varreq= oauth2.request(forURL:URL(string: signOutUriString)!, cachePolicy:.reloadIgnoringLocalAndRemoteCacheData)
req.httpMethod ="POST"lettask= oauth2.session.dataTask(with: req){ data, response, error in
if let response = response as?HTTPURLResponse, response.statusCode ==204{print("Sign out from server.")}else if let error = error {print(error)}}
task.resume()}}}privatefunc removeCookies(){HTTPCookieStorage.shared.removeCookies(since:Date.distantPast)print("All cookies deleted.")WKWebsiteDataStore.default().fetchDataRecords(ofTypes:WKWebsiteDataStore.allWebsiteDataTypes()){ records in
records.forEach{ record inWKWebsiteDataStore.default().removeData(ofTypes: record.dataTypes, for:[record], completionHandler:{})print("Cookie \(record) deleted.")}}}}
The text was updated successfully, but these errors were encountered:
Printing description of error:
▿ Optional<Error>
- some : Error Domain=com.apple.AuthenticationServices.WebAuthenticationSession Code=2 "Cannot start ASWebAuthenticationSession without providing presentation context. Set presentationContextProvider before calling -start." UserInfo={NSDebugDescription=Cannot start ASWebAuthenticationSession without providing presentation context. Set presentationContextProvider before calling -start.}
OAuth 5.3.2/ SwiftUI/ using macOS 13 run catalyst mode, will get this error:
Both iOS/Mac are OK, only catalyst can not work :(
The text was updated successfully, but these errors were encountered: