【问题标题】:How to completely Logout of Facebook SDK Auth in iOS App如何在 iOS 应用程序中完全注销 Facebook SDK Auth
【发布时间】:2017-10-20 21:21:40
【问题描述】:

使用 FBSDKCoreKit 4.22.1

我有一个公开安装的应用,白天为多个用户提供服务。一个人可以走到 iPad 前使用他们的 Facebook 帐户登录:

成功登录后,他们可以工作并使用该应用程序,但他们将在一段时间后注销:

注销成功。然后下一个用户上来使用公共 iPad 并点击 Facebook 登录按钮,但他们会看到:

FBSDKLoginManager 或其他 Facebook SDK 库已经记住了之前用户的 Facebook 登录的一些元素。

我想彻底清除之前用户的 Facebook 凭据的所有信息

成功注销后,调用此FBSDKLoginButtonDelegate 方法,我尝试了以下方法以完全删除 Facebook 帐户信息,但没有成功:

func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
    print("\(#function) in \(#file.components(separatedBy: "/").last ?? "")")
    print("Todo, must completely remove Facebook Auth token info for current user logging out")
    FBSDKAccessToken.setCurrent(nil)
    FBSDKLoginManager().logOut()
    FBSDKProfile.setCurrent(nil)
}

因此使用 FBSDKCoreKit 4.22.1 Safari 浏览器用于打开 Facebook 身份验证重定向 URL,而 Javascript 使用本地存储:

有趣的是,阻止所有 Cookie,Apple 暗示也将阻止网站数据 (localStorage),不会阻止本地存储和 Facebook,但仍会创建网站数据存储:

苹果说here

“更改接受哪些 Cookie 和网站数据:选择“Cookie 和网站数据”选项:”

  • “始终阻止:Safari 不允许任何网站、第三方或 广告商将 cookie 和其他数据存储在您的 Mac 上。这可能 阻止某些网站正常运行。”

这就是我希望本地存储和 cookie 一样被阻止的地方,但 Facebook 仍然可以创建本地存储条目

【问题讨论】:

  • 那个 SDK 可能使用 WebView 作为登录表单。您需要做的是删除此 Web 视图使用的 cookie 存储。
  • @uliwitness 好主意,我认为您肯定是对的,也许您仍然...我只是在模拟器上为 Safari “清除历史记录和网站数据”,但仍然遇到同样的问题.. .
  • @uliwitness 是网站数据,即存储信息,而不是 cookie,我猜它基本上是本地存储,没有办法停止这种存储
  • 本地存储可以通过 JavaScript 访问。因此,也许您可​​以找到一个删除给定域的本地存储的 JavaScript 并让您的网站运行它?
  • 请在这里查看我的答案stackoverflow.com/a/51039251/5093900 可能会有帮助。

标签: ios objective-c iphone swift facebook


【解决方案1】:

我遇到了类似的问题,我最终使用了 SDK 的修改版本,这实际上非常危险,因为其他开发人员可能不知道它已被修改..所以你需要留下注释..

问题:注销后,您仍然登录(在 Safari 中).. 但仅当您使用本机登录或系统登录时,无法从应用程序本身注销 Safari.. 超级烦人(您也无法从应用程序中清除 Safari 的 cookie 或数据)。

解决方案:

如果您查看 SDK 的文档,它会显示:

// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
//
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
// copy, modify, and distribute this software in source code or binary form for use
// in connection with the web services and APIs provided by Facebook.
//
// As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.




typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior)
{
  /*!
   @abstract This is the default behavior, and indicates logging in through the native
   Facebook app may be used. The SDK may still use Safari instead.
   */
  FBSDKLoginBehaviorNative = 0,
  /*!
   @abstract Attempts log in through the Safari or SFSafariViewController, if available.
   */
  FBSDKLoginBehaviorBrowser,
  /*!
   @abstract Attempts log in through the Facebook account currently signed in through
   the device Settings.
   @note If the account is not available to the app (either not configured by user or
   as determined by the SDK) this behavior falls back to \c FBSDKLoginBehaviorNative.
   */
  FBSDKLoginBehaviorSystemAccount,
  /*!
   @abstract Attemps log in through a modal \c UIWebView pop up

   @note This behavior is only available to certain types of apps. Please check the Facebook
   Platform Policy to verify your app meets the restrictions.
   */
  FBSDKLoginBehaviorWeb,
};

因此,如果您使用 Native 但它不能,它将回退到 Safari。如果您使用 System 但它不能,它会回退到 Native 回退到 Safari..

然后是 FBSDKLoginBehaviorWeb,它使用模态 web-view/popup!因此,如果您不是绝对必须使用 Native 或 System Login,那么我建议您选择此选项,因为它不会回退到 Safari。

否则: 这是我所做的更改,因此它永远不会在后台使用 Safari:

FBLoginSDKManager.m:

- (void)logInWithBehavior:(FBSDKLoginBehavior)loginBehavior
{
  NSDictionary *loginParams = [self logInParametersWithPermissions:_requestedPermissions];

  void(^completion)(BOOL, NSString *, NSError *) = ^void(BOOL didPerformLogIn, NSString *authMethod, NSError *error) {
    if (didPerformLogIn) {
      [_logger startAuthMethod:authMethod];
      _performingLogIn = YES;
    } else {
      if (!error) {
        error = [NSError errorWithDomain:FBSDKLoginErrorDomain code:FBSDKLoginUnknownErrorCode userInfo:nil];
      }
      [self invokeHandler:nil error:error];
    }
  };

  switch (loginBehavior) {
    case FBSDKLoginBehaviorNative: {
      if ([FBSDKInternalUtility isFacebookAppInstalled]) {
        [FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *loadError) {
          BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];
          if (useNativeDialog && loadError == nil) {
            [self performNativeLogInWithParameters:loginParams handler:^(BOOL openedURL, NSError *openedURLError) {
              if (openedURLError) {
                [FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors
                                   formatString:@"FBSDKLoginBehaviorNative failed : %@\nTrying FBSDKLoginBehaviorBrowser", openedURLError];
              }
              if (openedURL) {
                completion(YES, FBSDKLoginManagerLoggerAuthMethod_Native, openedURLError);
              } else {
                [self logInWithBehavior:FBSDKLoginBehaviorWeb];  //-- CHANGED BY BRANDON T.
              }
            }];
          } else {
            [self logInWithBehavior:FBSDKLoginBehaviorWeb];  //-- CHANGED BY BRANDON T.
          }
        }];
        break;
      }
        // intentional fall through.  -- CHANGED BY BRANDON T.
        [self logInWithBehavior:FBSDKLoginBehaviorWeb];  //-- CHANGED BY BRANDON T.
        break;
    }
    case FBSDKLoginBehaviorBrowser: {
      [self performBrowserLogInWithParameters:loginParams handler:^(BOOL openedURL,
                                                                    NSString *authMethod,
                                                                    NSError *openedURLError) {
        if (openedURL) {
          completion(YES, authMethod, openedURLError);
        } else {
          completion(NO, authMethod, openedURLError);
        }
      }];
      break;
    }
    case FBSDKLoginBehaviorSystemAccount: {
      [FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *loadError) {
        if (serverConfiguration.isSystemAuthenticationEnabled && loadError == nil) {
          [self beginSystemLogIn];
        } else {
          [self logInWithBehavior:FBSDKLoginBehaviorNative];
        }
      }];
      completion(YES, FBSDKLoginManagerLoggerAuthMethod_System, nil);
      break;
    }
    case FBSDKLoginBehaviorWeb:
      [self performWebLogInWithParameters:loginParams handler:^(BOOL openedURL, NSError *openedURLError) {
        completion(openedURL, FBSDKLoginManagerLoggerAuthMethod_Webview, openedURLError);
      }];
      break;
  }
}

这使得所有本机登录或系统登录都将回退到 modal-in-app UIWebView。然后你可以在注销时清除cookie,你会没事的。注销后将NSHTTPCookieStorage.sharedHTTPCookieStorage().cookiesNSURLCache.sharedURLCache().removeAllCachedResponses()全部删除。

显然最安全的选择是永远不要使用系统登录或本机登录,而是始终使用:FBSDKLoginBehaviorWeb..

【讨论】:

  • 谢谢@Brandon,虽然很痛苦,但对于软件开发职业课程来说,我正在尝试实施您的解决方案
【解决方案2】:

我可以通过将FBSDKLoginBehavior 更改为网络来解决我的这个问题,请参阅此处:https://stackoverflow.com/a/44101753/1258525

【讨论】:

  • 但是网络弹出窗口的弹出方式很愚蠢。我最接近的解决方案是显示一个提示,要求用户在 Safari 上注销,然后调用 UIApplication.shared.open(url: URL(string: "https://facebook.com")!) 将他们带到那里。它破坏了应用程序的流程,但确实将它们完全注销(如果他们按照指示在 Safari 上注销):(。我想知道 Facebook SDK 如何存储凭据,以便 Safari 知道该特定用户已登录。任何人都知道如何他们在做吗?如果我知道怎么做,也许我可以用我自己隐藏的 WKWebView 来自动化它。
【解决方案3】:

在这里,我将描述用户如何使用 Facebook 原生应用从您的应用中注销: https://stackoverflow.com/a/51039251/5093900

【讨论】:

    猜你喜欢
    • 2014-09-05
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    相关资源
    最近更新 更多