在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
EDIT2:我试过了
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)"
EDIT3:我试过清空钥匙链
let secItemClasses = [kSecClassGenericPassword,
kSecClassInternetPassword,
kSecClassCertificate,
kSecClassKey,
kSecClassIdentity]
for secItemClass in secItemClasses {
let dictionary = [kSecClass as String:secItemClass]
SecItemDelete(dictionary as CFDictionary)
}
但是,我可能需要使用属性keychainAccountForClientCredentials
和keychainAccountForTokens
,那么是否可以访问存储在这些密钥链中的数据呢?
1条答案
按热度按时间von4xj4u1#
我已经解决了这个问题,我只需要为SFSafariView控制器清理cookie(我已经在PHP中做到了这一点)