Clean OAuth2 token in swift

In swift I'm calling successfully a callback URL which revoke a token after the user is logout, and right after I call this to enable re-logging

func runOauth(){
    self.loadingLabel.isHidden=true
    let appDelegate = UIApplication.shared.delegate as! AppDelegate

    appDelegate.oauth2!.logger = OAuth2DebugLogger(.debug)
    
    //code executed when OAuth have finished
    appDelegate.oauth2!.afterAuthorizeOrFail = self.callBackOAuth
    

    var url:URL?
    do{
        //the url for authorizing the user, kronos://oauth/callback" is called after the OAuth finish
        url = try appDelegate.oauth2!.authorizeURL(withRedirect:"kronos://oauth/callback", scope: "auth",params: ["tg":"addon/kronos/main","idx":"login.OAuth","formId":"iOS"])
        do{
            let authorizer = appDelegate.oauth2!.authorizer as! OAuth2Authorizer
            //launch OAuth in embeded view "SafariVC"
            print("Safari embeded")
            safariVC = try authorizer.authorizeSafariEmbedded(from: self,at: url!)
            
        }catch let error {
            DispatchQueue.main.async {
                print("ERROR authorizing\(error)")
                //self.runOauth()
            }
        }
    }catch let error {
        DispatchQueue.main.async {
            print("ERROR creating OAuth URL \(error)")
            //self.runOauth()
        }
    }
}

But it re-log the user automatically when loading logging page, I've tried this:

let appDelegate = UIApplication.shared.delegate as! AppDelegate
        
 let authorizer = appDelegate.oauth2!.authorizer as! OAuth2Authorizer
 authorizer.oauth2.forgetTokens()

Does someone have a solution?

EDIT: In fact the first logoff woks well but if I relog I can not sign off anymore and I have that line in the console when it fail [Debug] OAuth2: Did exchange code for access [true] and refresh [true] tokens

EDIT2: I've tried

appDelegate.oauth2?.forgetClient() appDelegate.oauth2 = OAuth2CodeGrant(settings: OAuthParams ) appDelegate.oauth2!.authConfig.authorizeContext = KronosWebsite?.window//KronosWebsite the WKWebview runOauth()`

and in the console I've this now [Debug] OAuth2: Forgetting client credentials and removing them from keychain [Warn!] OAuth2: Failed to delete credentials from keychain: Error Domain=swift.keychain.error Code=-25300 "(null)"

I've tried to empty keychain but maybe I need to access data stored with accounts keychainAccountForClientCredentials and keychainAccountForTokens, is this possible and how?

I've solved this issue, I just had to clean cookies for the SFSafariViewController (I've done that in PHP)

Clean OAuth2 token in swift
 
 
Q