使用ADAL进行身份验证-注销问题

时间:2019-04-09 16:11:28

标签: ios swift azure azure-active-directory adal

我正在使用SWIFT 4编写IOS应用程序编码,并且正在使用ADAL框架来对用户进行身份验证。我设置了诱因,一切顺利,直到注销为止。 当我从应用程序注销用户时,该应用程序将删除cookie。尝试发出注销并以其他用户身份登录时,Azure AD仍然会看到以前的cookie。

以下退出功能的代码:

@IBAction func signoutButton(_ sender: Any) {

    displaySelectionController.isHidden = true
    self.signoutButton.isEnabled = false
    self.signoutButton.backgroundColor = #colorLiteral(red: 0.7018831372, green: 0.7020055652, blue: 0.7018753886, alpha: 1)
    connectedLabel.isHidden = true
    connectedTextInfo.isHidden = true
    callGraphButton.isHidden = false
    displaySelectionController.isHidden = true

    let request = NSMutableURLRequest(url: NSURL(string: "https://login.microsoft.com/logout")! as URL)
    request.httpMethod = "GET"

    guard let account = currentAccount()?.userInformation?.userId else {
        self.updateLogging(text: "Didn't find a logged in account in the cache.")
        return
    }

    ADKeychainTokenCache.defaultKeychain().removeAll(forUserId: account, clientId: kClientID, error: nil)

    let cookieJar = HTTPCookieStorage.shared
    guard let cookies = cookieJar.cookies else { return }
    let cookiesArr = Array(cookies)
    for cookie: HTTPCookie in cookiesArr {
        if (cookie.name == "SignInStateCookie" || cookie.name == "ESTSAUTHPERSISTENT" || cookie.name == "ESTSAUTHLIGHT" || cookie.name == "ESTSAUTH" || cookie.name == "ESTSSC") {
            cookieJar.deleteCookie(cookie)
            print("     COOKIE DELETED")
        }
    }

    self.updateLogging(text: "Removed account for: \(account)" )
}

1 个答案:

答案 0 :(得分:0)

我通过更改删除Cookie的方式来解决问题:

@IBAction func signoutButton(_ sender: Any) {

    displaySelectionController.isHidden = true
    self.signoutButton.isEnabled = false
    self.signoutButton.backgroundColor = #colorLiteral(red: 0.7018831372, green: 0.7020055652, blue: 0.7018753886, alpha: 1)
    connectedLabel.isHidden = true
    connectedTextInfo.isHidden = true
    callGraphButton.isHidden = false
    displaySelectionController.isHidden = true

    ADKeychainTokenCache.defaultKeychain().removeAll(forClientId: kClientID, error: nil)

    _ = HTTPCookie.self
    let cookieJar = HTTPCookieStorage.shared

    for cookie in cookieJar.cookies! {
        cookieJar.deleteCookie(cookie)
    }
}