facebook-ios-sdk 注销问题

发布于 2024-11-11 14:40:17 字数 1164 浏览 5 评论 0原文

我在这里看到了很多有关 Facebook Graph API 的问题,但我仍然没有找到使用它进行简单“登录”/“注销”操作的解决方案。看起来单点登录风格造成的混乱多于好处。

我想知道是否可能出现以下情况:

  1. 进入应用程序(未创建accessToken/expirationDate)。
  2. 通过调用 authorize:delegate: 方法使用 SSO 执行登录(应用程序进入后台并在“全局”范围(Facebook 应用程序/移动 Safari)中进行登录,要求提供用户凭据。
  3. 回车在应用程序中(现已登录,accessTokenexpirationDate 均保存到 NSUserDefaults),
  4. 通过调用 logout 执行注销:方法(现已注销,accessTokenexpirationDate 均从 NSUserDefaults 中删除)
  5. 尝试再次执行登录,使用完全相同的方法2. 中完成的步骤

我意识到,当我调用 logout: 时,我确实从我的应用程序范围内从 Facebook 注销(accessToken 已失效),而不是从global 范围(Facebook 应用程序/移动 Safari)。在 5.) 中,当我尝试再次登录时,应用程序会转到后台,并在 Facebook 中再次尝试登录。应用程序/移动 Safari 和往常一样,但是我收到一个屏幕,显示我已经登录:

您已经授权...。按“确定”继续。 以 ... 身份登录(不是您?)。

对于刚刚在我的应用程序中注销的用户来说,这是一种奇怪的行为。 我的问题是:

“我可以真的从我的应用程序内部从 facebook(我的意思是“全球”范围)注销吗?这也会影响使用 facebook 凭据的其他应用程序。但是,如果我不能为此,我怎样才能避免上述“奇怪的行为”

I have seen a lot of questions here regarding the Facebook Graph API but I still haven't find a solution for simple 'login'/'logout' operations using it. Looks like the Single Sign-On style is causing more confusion than benefits.

I'd like to know if it is possible have the following situation:

  1. Enter in the app (no accessToken/expirationDate created).
  2. Perform a login using SSO by calling authorize:delegate: method (application goes background and the login is made in the 'global' scope (Facebook App/Mobile Safari), asking for the user credentials.
  3. Enter back in the app (now logged in, both accessToken and expirationDate are saved to NSUserDefaults).
  4. Perform a logout by calling the logout: method (now logged out, both accessToken and expirationDate are removed from NSUserDefaults)
  5. Attempt to perform a login again, with exactly the same steps done in 2.

I realize that when I call logout:, I do really log out from Facebook (accessToken is invalidated) from my App scope, not from the global scope (Facebook App/Mobile Safari). In 5.) when I try to log in again, the application goes to background and the login attempt is made again in Facebook App/Mobile Safari as usual, however I'm getting a screen saying that I'm already logged in:

You have already authorized .... Press "Okay" to continue.
Logged in as ... (Not You?).

It's a strange behavior for the user that has just logged out in my App.
My question is:

"Can I really log out from facebook (I mean 'global' scope) from inside my App? This would affect other apps using the facebook credentials too. However, if I can't to do this, how can I avoid the 'strange behavior' describe above?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

你是暖光i 2024-11-18 14:40:17

爱德华多,

我感受到你的痛苦!我花了一天的大部分时间来研究这个问题。我发现,当您使用 SSO 和调用时:

从您的代码调用:

[facebook logout:self];

Facebook API 方法:

- (void)logout:(id<FBSessionDelegate>)delegate {

  self.sessionDelegate = delegate;
  [_accessToken release];
  _accessToken = nil;
  [_expirationDate release];
  _expirationDate = nil;

  NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];

  for (NSHTTPCookie* cookie in facebookCookies) {
    [cookies deleteCookie:cookie];
  }

  if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogout)]) {
    [_sessionDelegate fbDidLogout];
  }
}

facebook API 确实会使访问令牌和过期日期变量无效并尝试删除移动 Safari cookie,但由于某种原因,可能是 Apple 的错误,cookie 并未真正删除。因此,当您下次尝试登录时,您的移动 Safari 将看到该 cookie,并显示:

"You have already authorized .... Press "Okay" to continue. Logged in as ... (Not You?)."

在 Facebook 找到修复程序或 Apple 修复其损坏的 API 之前,我们必须通过 Safari 绕过 SSO。以下是我为了强制使用旧的登录对话框而对 Facebook.m 所做的更改。如果您使用这些更改,它们可能不会永远有效,但我猜它们会持续很长时间。另外,为了确保这适用于最新的 facebook API,我已将其更新到本文中的最新版本(2011 年 11 月构建)。

从您的代码调用:

[facebook authorize:permissions];

Facebook API 方法:

- (void)authorize:(NSArray *)permissions {
  self.permissions = permissions;

//  [self authorizeWithFBAppAuth:YES safariAuth:YES];
    [self authorizeWithFBAppAuth:NO safariAuth:NO];
}

如果这对您有帮助,请评价此帖子和我的帖子,以帮助其他人找到它。

gadildafissh

Eduardo,

I feel your pain! I spent the better part of a day working on this issue. I have discovered that when you use SSO and the call:

Called from your code:

[facebook logout:self];

Facebook API method:

- (void)logout:(id<FBSessionDelegate>)delegate {

  self.sessionDelegate = delegate;
  [_accessToken release];
  _accessToken = nil;
  [_expirationDate release];
  _expirationDate = nil;

  NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];

  for (NSHTTPCookie* cookie in facebookCookies) {
    [cookies deleteCookie:cookie];
  }

  if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogout)]) {
    [_sessionDelegate fbDidLogout];
  }
}

The facebook API does invalidate the access token and expirationdate variables and attempts to delete the mobile Safari cookies, but for some reason, probably Apple's fault the cookies are not really deleted. So when you attempt to login in the next time your mobile Safari will see the cookie and it says:

"You have already authorized .... Press "Okay" to continue. Logged in as ... (Not You?)."

Until either Facebook finds a fix or Apple fixes their broken API we must bypass SSO through Safari. Below are the changes I made to Facebook.m in order to force the old login dialog. If you used these changes they may not work forever but it is my guess that they will work for a very long time. Also to be sure this worked with the most recent facebook API I updated to the latest as of this post (Nov 2011 build).

Called from your code:

[facebook authorize:permissions];

Facebook API method:

- (void)authorize:(NSArray *)permissions {
  self.permissions = permissions;

//  [self authorizeWithFBAppAuth:YES safariAuth:YES];
    [self authorizeWithFBAppAuth:NO safariAuth:NO];
}

If this helps you please up rate this thread and my post to help others find it.

gadildafissh

去了角落 2024-11-18 14:40:17

恐怕答案是否定的,你不能这样做。

您的应用程序位于沙箱中,无法在外部写入,其中全局cookie(用于移动Safari)和Facebook应用程序设置(我认为在Facebook应用程序首选项/cookies中)

您只能警告您的用户在您的应用程序之外注销。 ..

...或者您可以不使用 facebook api SSO,而是在应用程序登录 Web 表单中使用,就像我出于其他原因所做的那样。

如果您选择该选项此拉取请求可能会节省您一些时间;)

I'm afraid the answer is no, you can't do this.

Your application is in a sandbox, and can't write outside, where global cookies are (for mobile safari) and Facebook app settings (in Facebook app preferences/cookies I think)

You can only warn your user to logout outside of your app...

...Or you can just not use facebook api SSO, but in app login webform, like I do for other reasons.

If you choose that option this pull request might save you some time ;)

勿忘心安 2024-11-18 14:40:17

Hii,

这是不可能的,原因是单点登录(SSO)并不是让用户每次登录,他都会注销,而是如果用户登录任何启用 FB 的应用程序 - 它将使用它再次登录 - 这是因为该设备主要由单人使用,在这种情况下,只有一个用户可以登录 Facebook。

您无法控制您的应用程序之外的任何应用程序 - 例如 - 如果您使用 Gmail 和 Google 登录当您打开 google.com 时,您可以看到当前登录的用户名具有 SSO,

Hii ,

its not possible , the reason is for Single Sign On (SSO) is not to make user login everytime, he logouts , instead if the user logs in anyone of FB enabled apps - it will use that to login again - This is because the device is mostly used by single person in this case only one user can login in Facebook.

you can't control any app outside of your app - for Example - if u login with Gmail & when you open google.com you can see your username there is currently logged In which has SSO,

云巢 2024-11-18 14:40:17

在 Facebook 的新 SDK 中,您可以设置登录按钮 loginBehaviour 属性,

下面的代码是 swift ...

let fbButton = FBSDKLoginButton()
fbButton.loginBehavior = .Web

In new SDK of Facebook, you can set login button loginBehaviour property

Below code in swift ...

let fbButton = FBSDKLoginButton()
fbButton.loginBehavior = .Web
无法回应 2024-11-18 14:40:17

答案已经完成,但我只是想澄清一下。也许它节省了某人的时间。

转到 Facebook.m 并将行更改

  [self authorizeWithFBAppAuth:YES safariAuth:YES];

  [self authorizeWithFBAppAuth:YES safariAuth:NO];

这将导致登录窗口出现在应用程序内。注销将完美运行。换句话说,它将像在旧版本操作系统中一样工作。

Answer already done, but I just want to clarify it. May be it saved somebody's time.

Go to Facebook.m and change line

  [self authorizeWithFBAppAuth:YES safariAuth:YES];

to

  [self authorizeWithFBAppAuth:YES safariAuth:NO];

It will cause login window appear inside the app. Logout will work perfect. In other words, it will work as it used to in older versions of OS.

笑咖 2024-11-18 14:40:17

除了 kishnan94 的答案。 Objective C 版本是;

如果您想要打开一个模式并独立于 Safari 或 Facebook 应用程序请求 facebook 凭据,只需使用最新的 facebook sdk 并设置登录行为,

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login setLoginBehavior:FBSDKLoginBehaviorWeb];

这将使注销过程更加方便,并且对于不使用 safari 或 facebook 应用程序的用户来说不会那么混乱账户。

in addition to kishnan94 answer. the objective c version is ;

if you want a modal to open up and ask for facebook credentials seperately from Safari or Facebook app, just use the latest facebook sdk and set the login behaviour

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login setLoginBehavior:FBSDKLoginBehaviorWeb];

this will make the logout process more convenient and less confusing for users without using safari or facebook app accounts.

紙鸢 2024-11-18 14:40:17

看来这是Facebook SDK的一个bug。如果设备上安装了 Facebook 应用程序,则更新 access_token。另一方面,access_tokenexpirationDate 无法更改。 :((

It seems that this is a bug of Facebook SDK. In a case of the Facebook app is installed on device, access_token is renewed. In other hand, access_token and expirationDate could not be changed. :((

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文