如何在iOS应用程序中完全注销Facebook SDK验证
使用FBSDKCoreKit 4.22.1 我公开安装了一个应用程序,白天为多个用户提供服务。一个人可以走到iPad前,使用他们的Facebook帐户登录: 成功登录后,than可以完成工作并使用应用程序,稍后将注销: 注销成功。然后,下一个用户出现在公共iPad上并单击Facebook登录按钮,但他们会看到: FBSDKLoginManager或其他Facebook SDK库已记住前一用户Facebook登录的某些元素 我想完全清除关于前一个用户的Facebook凭据的所有信息 成功注销后,将调用此如何在iOS应用程序中完全注销Facebook SDK验证,ios,objective-c,iphone,swift,facebook,Ios,Objective C,Iphone,Swift,Facebook,使用FBSDKCoreKit 4.22.1 我公开安装了一个应用程序,白天为多个用户提供服务。一个人可以走到iPad前,使用他们的Facebook帐户登录: 成功登录后,than可以完成工作并使用应用程序,稍后将注销: 注销成功。然后,下一个用户出现在公共iPad上并单击Facebook登录按钮,但他们会看到: FBSDKLoginManager或其他Facebook SDK库已记住前一用户Facebook登录的某些元素 我想完全清除关于前一个用户的Facebook凭据的所有信息 成功注销后
fbsdkloginbuttonelegate
方法,我尝试了以下操作以完全删除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(苹果暗示这也会阻止网站数据(localStorage))并不会阻止本地存储和Facebook,还会创建网站数据存储:
苹果说:
更改接受的Cookie和网站数据:选择“Cookie和网站数据”选项:
- “始终阻止:Safari不允许任何网站、第三方或 广告商在你的Mac电脑上存储cookies和其他数据。这可能会导致 阻止某些网站正常工作。”
这就是我希望本地存储和cookie一样被阻止的地方,但Facebook仍然可以创建本地存储条目我遇到了类似的问题,我最终使用了SDK的修改版本,这实际上相当危险,因为其他开发人员可能不知道它被修改了。。所以你需要留个条子 问题:注销后,您仍然登录(在Safari中)。。但前提是您使用本机登录或系统登录,并且无法从应用程序本身中注销Safari。。超级烦人(你也无法从应用程序中清除Safari的cookies或数据) 解决方案: 如果查看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。若你们使用了这个系统,但它不能,那个么它会回到原生版本,这会回到Safari
然后是FBSDKLoginBehaviorWeb,它使用模式web视图/弹出窗口!因此,如果您不一定要使用本机或系统登录,那么我建议您选择此选项,因为它不会退回到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;
}
}
这使得所有本机登录或系统登录都会退回到appUIWebView
中的模式。然后你可以在注销时清除cookies,你就会没事了。。注销后删除所有nshttpookieStorage.sharedhttpookieStorage().cookies
和NSURLCache.sharedURLCache()。删除所有缓存响应()
显然,最安全的选择是从不使用系统或本机登录,而是始终使用:FBSDKLoginBehaviorWeb
。我可以通过将FBSDKLoginBehavior
更改为web来解决此问题,请参见此处:此处我正在描述用户如何使用Facebook本机应用程序从应用程序注销:
SDK可能使用WebView作为登录表单。您需要做的是删除此web视图使用的cookie存储。@uliwitness好主意,我确信您是对的,也许您仍然…我只是在我的模拟器上为Safari“清除历史和网站数据”,仍然存在相同的问题…@uliwitness这是网站数据,即存储了信息,而不是cookie,它基本上是本地存储,我想,没有办法阻止这种存储本地存储可以从JavaScript访问。所以也许你可以找到一个JavaScript,删除一个给定的域名的本地存储,让你的网站运行它。请在这里检查我的答案,也许它可以帮助。谢谢布兰登,这是一个痛苦,对于软件开发的职业课程,尽管LOL,我正在尝试实现你的解决方案,但网络弹出是高飞,它是如何弹起。我拥有的最接近的解决方案是显示一个提示,要求用户注销Safari,然后调用UIApplication.shared.open(url:url(字符串):https://facebook.com)
将他们带到那里。它中断了应用程序的流程,但确实会将其完全注销(如果他们按照说明并在Safari上注销):(.我想知道Facebook SDK是如何存储凭据的,以便Safari知道该特定用户已登录。有人知道他们是如何操作的吗?如果我知道如何操作,或许我可以使用自己隐藏的WKWebView将其自动化。