How to LogOut from iOS ADAL Authentication?

后端 未结 3 1126
半阙折子戏
半阙折子戏 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:27

    An update to Rich's excellent answer. First, the interface has changed with the latest ADAL release and you need to access the token cache this way:

    #import 
    [...]
    [[ADKeychainTokenCache defaultKeychainCache] removeAllForClientId:ADFS_CLIENT_ID error:&error];
    

    And to clear the cookies, I recommend just deleting the ones that matter instead of clearing them all:

    NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (NSHTTPCookie *cookie in [cookieJar cookies]) {
        if ([cookie.name isEqualToString:@"MSISAuth"] ||
            [cookie.name isEqualToString:@"MSISAuthenticated"] ||
            [cookie.name isEqualToString:@"MSISLoopDetectionCookie"]) {
            [cookieJar deleteCookie:cookie];
        }
    }
    

    (I found that AD_PROMPT_ALWAYS didn't work on older ADFS installations and was forced to delete cookies.)

提交回复
热议问题