How to LogOut from iOS ADAL Authentication?

后端 未结 3 1082
半阙折子戏
半阙折子戏 2021-02-09 05:23

I have integrated ADAL library into my iOS application and it\'s working fine. But now I want to log out from ADAL. How can I do log out?

3条回答
  •  情歌与酒
    2021-02-09 05:44

    This swift 3 code worked for me (ADAL 2.5.1):

    Destroy the keystore:

    guard let clientId = getAuthConfig().clientId else {
                // freak out
                print("Auth.logout: I freaked out getting the client ID ")
                return
            }
            ADKeychainTokenCache.defaultKeychain().removeAll(forClientId: clientId, error: nil)
    

    And clear the cookies:

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

提交回复
热议问题