简体   繁体   English

即使从Facebook应用程序设置中删除了应用程序,用户仍然可以访问应用程序

[英]User able to access app even after removing app from Facebook App Settings

I have an app that uses both Parse and FacebookSDK. 我有一个同时使用Parse和FacebookSDK的应用程序。 Currently running into the problem where the user is still able to access my app even when going to their Facebook account App settings and removing my app from accessing their Facebook data. 当前遇到的问题是,即使转到其Facebook帐户“应用程序设置”并从访问其Facebook数据中删除我的应用程序,用户仍然仍然可以访问我的应用程序。

So: 所以:
1: New user does a fresh install. 1:新用户执行全新安装。
2: User signs up via Facebook Login and accesses app 2:用户通过Facebook登录进行注册并访问应用
3: User goes to Facebook.com>App Settings>Remove my app 3:用户转到Facebook.com>应用设置>删除我的应用
4: Back on iPhone, user closes app, reopens and gains access again 4:回到iPhone,用户关闭应用程序,重新打开并再次获得访问权限

Here is where I check the current status of the user and let them have access if they hold a currentAccessToken 这是我检查用户当前状态的地方,如果他们持有currentAccessToken ,则让他们可以访问

override func viewDidLoad() {
    super.viewDidLoad()

    if FBSDKAccessToken.currentAccessToken() != nil{
        moveToNextView() //Segue to next viewController
    }
}

And my AppDelegate.swift : 和我的AppDelegate.swift

import UIKit
import Parse

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {

        Parse.setApplicationId("ID", clientKey:"KEY")
        PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
        FBSDKProfile.enableUpdatesOnAccessTokenChange(true)


        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    }


    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
    }
}

I'm guessing the currentAccessToken is cached somewhere on the app or device, but unsure about how to clear/refresh that cache. 我猜想currentAccessToken缓存在应用程序或设备上的某个地方,但是不确定如何清除/刷新该缓存。

I have found the solution to this problem. 我已经找到解决此问题的方法。 It's not as straight forward as one would think. 它并不像人们想象的那样直接。 The Facebook developer console allows you to set a Deauthorize Callback URL which can be found here: Facebook开发人员控制台允许您设置取消授权回调URL ,可以在以下位置找到该URL

  1. Select your app in the Facebook developer dashboard 在Facebook开发人员仪表板中选择您的应用
  2. Click Facebook Login on the side menu 单击侧面菜单上的Facebook登录。
  3. Click Settings 点击设置
  4. Then uou can supply Deauthorize Callback URL 然后,您可以提供取消授权回调网址

Whenever someone removes your app from facebook it generates a POST to your callback URL with a signed request parameter. 每当有人从Facebook删除您的应用程序时,它就会生成带有签名请求参数的POST到您的回调URL。 You can parse the signed request to retrieve the user's facebookid. 您可以解析已签名的请求以检索用户的facebookid。 Once you have the user's facebookid you can update a record in your database that you can use to check on their next login. 获得用户的facebookid后,您可以更新数据库中的记录,可用于检查他们的下一次登录。

Here is an example in PHP of how to handle the deauthorize callback 这是PHP中如何处理取消授权回调的示例

<?php

function parse_signed_request($signed_request) {
  list($encoded_sig, $payload) = explode('.', $signed_request, 2);

  $secret = "appsecret"; // Use your app secret here

  // decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);

  // confirm the signature
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if ($sig !== $expected_sig) {
    error_log('Bad Signed JSON signature!');
    return null;
  }

  return $data;
}


$signed_request = $_POST['signed_request'];
$data = parse_signed_request($signed_request);
$user_id = $data['user_id'];

//now use the user_id to look up your user in your database
//update a field called deauthorized to true so that you 
//can check this value upon next login

?>

Now next time you check the your access token include a check in your database to see if the user has removed the app. 现在,下次您检查访问令牌时,请在数据库中添加一个检查项,以查看用户是否已删除该应用程序。

- (void)viewDidLoad
{
  [super viewDidLoad];
  if ([FBSDKAccessToken currentAccessToken]) {
     // User is logged in, but they may have
     // removed the app so we have to check our 
     // db using a REST API call to see if is deauthorized

     // If the user has deauthorized then log them out
     // send them back to the login/signup page
     // if not, carry on as usual

     //also don't forget to set the deauthorized value to 0
     //whenever a user successfully logs into facebook

  }
}

Hopefully this will help someone in the future. 希望这会在将来对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift:即使从Facebook设置中删除了应用程序,也始终返回Facebook访问令牌 - Swift: Facebook Access Token is always returned even after removing App from Facebook settings 即使从Facebook设置中删除了应用程序,AccessToken仍然存在 - AccessToken still exists even after removing an app from Facebook settings 使用Facebook应用后,Facebook用户帐户在iOS设置中仍然为空 - Facebook user account remains empty in iOS settings after using Facebook app 在iOS中检测用户是否通过应用设置从Facebook删除了他的应用或更改了密码 - In iOS Detect whether user removed his app from Facebook via app settings or changed password Facebook SDK 3.1 iOS:如果用户从Facebook设置中删除应用,则处理登录 - Facebook SDK 3.1 iOS: Handle login if user remove app from Facebook Settings 如何从另一个 App IOS 打开 Facebook 应用设置? - How to open Facebook app settings from another App IOS? 用户在应用程序上使用“使用Facebook登录”后,如何访问Facebook访问令牌? - How to access a Facebook access token after a user has used “log in with Facebook” on an app? iOS 中的访问设置应用程序 - Access Settings app in iOS 用户使用Facebook登录后,应用崩溃 - App crashes after user logs in with Facebook 即使在删除 AdMob 后也无法删除应用程序隐私 - Cannot remove App Privacy even after removing AdMob
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM