清除swift中的OAuth2令牌



在swift中,我成功地调用了一个回调URL,该URL在用户注销后撤销令牌,并且在我调用该URL后立即启用重新登录

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()
}
}
}

但当加载日志页面时,它会自动重新记录用户,我尝试过这个:

let appDelegate = UIApplication.shared.delegate as! AppDelegate

let authorizer = appDelegate.oauth2!.authorizer as! OAuth2Authorizer
authorizer.oauth2.forgetTokens()

有人有解决方案吗?

编辑:事实上,第一次注销很好,但如果我重新登录,我就不能再注销了,当失败时,我在控制台上有那行

[Debug] OAuth2: Did exchange code for access [true] and refresh [true] tokens

第2版:我试过

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()

我在控制台里有这个

[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)"

第3版:我试着清空钥匙链

let secItemClasses = [kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity]
for secItemClass in secItemClasses {
let dictionary = [kSecClass as String:secItemClass]
SecItemDelete(dictionary as CFDictionary)
}

但是,也许我需要使用属性keychainAccountForClientCredentialskeychainAccountForTokens,所以可以访问存储在这些钥匙链中的数据吗?

我已经解决了这个问题,我只需要清理SFSafariViewController的cookie(我在PHP中做过(

最新更新