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-logging 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
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.oauth2?.forgetClient()
appDelegate.oauth2 = OAuth2CodeGrant(settings: OAuthParams )
appDelegate.oauth2!.authConfig.authorizeContext = KronosWebsite?.window//KronosWebsite the WKWebview
runOauth()
and I've this in the console
[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)"
EDIT3: I've tried to empty keychains
let secItemClasses = [kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity]
for secItemClass in secItemClasses {
let dictionary = [kSecClass as String:secItemClass]
SecItemDelete(dictionary as CFDictionary)
}
But maybe I need to use attributes keychainAccountForClientCredentials
and keychainAccountForTokens
, so is this possible to access data stored in those keychains?