parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Facebook link/unlink issue

Open dbezborodov opened this issue 10 years ago • 10 comments

Hello, we have an issue with Facebook link/unlink: it works fine using original parse API, but in parse-server it ends up with code 206 "Cannot modify user". Just tested with v.2.2.9, the issue is still there. I saw that error mentioned in many issues before, but could not find any solution yet.

Requests were as: Request: GET /app/sessions/me HTTP/1.1 X-Parse-Session-Token: r:92c7783abc7aa7be51d230459ee8d4db

Response: { "sessionToken": "r:92c7783abc7aa7be51d230459ee8d4db", "user": { "__type": "Pointer", "className": "_User", "objectId": "TSMhgHDhlN" }, "createdWith": { "action": "signup", "authProvider": "facebook" }, "restricted": false, "expiresAt": { "__type": "Date", "iso": "2017-05-11T15:08:53.518Z" }, "updatedAt": "2016-05-11T15:08:53.518Z", "createdAt": "2016-05-11T15:08:53.518Z" }

Request: PUT /app/classes/_User/TSMhgHDhlN HTTP/1.1 X-Parse-Session-Token: r:92c7783abc7aa7be51d230459ee8d4db {"authData":{"facebook":null}}

Response: {"updatedAt": "2016-05-11T15:10:00.980Z"}

Request: POST /app/login HTTP/1.1 {"_method":"GET","username":"user1","password":"1234"}

Response: { "objectId": "TSMhgHDhlN", "username": "user1", "createdAt": "2015-12-03T08:41:50.980Z", "updatedAt": "2016-05-11T15:10:00.980Z", "facebookId": "", "sessionToken": "r:2ad8dd42708b8bea16feb23c1a13b549" }

Request: PUT /app/classes/_User/TSMhgHDhlN HTTP/1.1 X-Parse-Session-Token: r:2ad8dd42708b8bea16feb23c1a13b549 {"password":"1234","facebookId":{"__op":"Delete"},"email":"email","username":"user2","sCountryName":"country","sLanguageCode":"en","sCountryCode":"code"}

Response: {"updatedAt": "2016-05-11T15:10:02.274Z"}

Request: PUT /app/classes/_User/TSMhgHDhlN HTTP/1.1 X-Parse-Session-Token: r:2ad8dd42708b8bea16feb23c1a13b549 {"authData":{"facebook":{"id":"","access_token":"","expiration_date":"2016-07-10T13:35:59.996Z"}}}

Response: {"code":206,"error":"cannot modify user TSMhgHDhlN"}

dbezborodov avatar May 11 '16 16:05 dbezborodov

Same issue but with twitter. It is very weird it only happens with some users

ajamaica avatar May 11 '16 18:05 ajamaica

Same issue here when Facebook user upgrade to our own parse server. any work around? Right now the only way is to force user to re-login again. :-/

Update: We found the problem, it actually related to session stuff

pungme avatar May 12 '16 12:05 pungme

We have lots of passing test cases that cover these features. Can you post some code that reliably reproduces your issue? Ideally as a test case we can add to our test suite.

drew-gross avatar May 12 '16 23:05 drew-gross

ok, some more information and sample code here.

It seems the bug is somehow related to link/unlink operations from PFFacebookUtils framework. The latest Parse SDK v.1.12.0 is used. The bug can be reproduced, for example, if I login as Facebook PFUser initially. Then, for example, I want to change my registered email. In that case I need to unlink from Facebook and update the email field. If I then immediately want to be registered as Facebook, using new Facebook account email, then I need to link the current PFUser with Facebook account and updated again the email field. In that case I get the error “cannot modify user” immediately after the method returns response [PFFacebookUtils linkUserInBackground:[PFUser currentUser] withAccessToken:token block:^(BOOL succeeded, NSError * _Nullable error) {}; So, neither of these two link/unlink operations does not work properly.

Need to mention, that currently on live parse server, this kind of behaviour works well without any errors, but not on parse server.

Unlinking:

if ([PFFacebookUtils isLinkedWithUser:[PFUser currentUser]]) { // unlink the current user from facebook and change the registered email
        [PFFacebookUtils unlinkUserInBackground:[PFUser currentUser] block:^(BOOL succeeded, NSError * _Nullable error) {

        if (succeeded) {
            [[ParseService sharedInstance] updateUser:email andPassword:pass WithBlock:^(BOOL success) {
                // ….
            };
        } else {
            // … 
        }
    }

Linking:

NSArray *permissionsArray = @[@"public_profile", @"email", @"user_friends"];
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];

    [login logInWithReadPermissions:permissionsArray fromViewController:controller handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {
            // ...
        } else {

            // ...

            FBSDKAccessToken *token = [FBSDKAccessToken currentAccessToken];
            [login logOut];

            // ...

            [PFFacebookUtils linkUserInBackground:[PFUser currentUser] withAccessToken:token block:^(BOOL succeeded, NSError * _Nullable error) {

                if (error) {
                    if (block) {
                        block(nil, NO, error);
                    }
                }

                [[ParseService sharedInstance] updateUserForFacebook:facebookEmail facebookId:facebookId accessToken:token WithBlock:^(BOOL success) {

                    if (success) {
                        if (block) {
                            block(facebookEmail, YES, nil);
                        }
                    } else {
                        if (block) {
                            block(nil, NO, error);
                        }
                    }
                }];
            }];
        }
    }];

dbezborodov avatar May 13 '16 10:05 dbezborodov

OK, so your request flow is:

  1. Sign up with facebook
  2. Unlink Facebook
  3. Change email address
  4. Relink with Facebook <-- this is the one that fails.

is that correct?

drew-gross avatar May 13 '16 16:05 drew-gross

My users lost the session after any _User save operation. what I did is manually remove the authData from de db and now relink. It is very weird

ajamaica avatar May 13 '16 16:05 ajamaica

@drew-gross: Basically yes, I will explain more: the app has the re-registration option. So, for example, I’ve already signed up via Facebook, and as the user want to change my registered email for my parse account (PFUser).

In this way, the user has 2 options:

  1. change email to another one - in that case I need to unlink user from Facebook account (PFfacbookUtils unlink method) and update the email and username field;
  2. other option - if I was registered via simple email registration and want to re-register as Facebook user, I need to link current user and update the email field with email from Facebook.

The issue happens, when I was signed up as Facebook user. I change the registered email (and also unlink user from Facebook), then almost immediately I want to reregister as Facebook again (link user to Facebook). At this point I encounter the errors, while on live parse it works well without issues.

dbezborodov avatar May 16 '16 07:05 dbezborodov

Any ideas when that might be fixed?

dbezborodov avatar Jun 01 '16 07:06 dbezborodov

Closing due to lack of activity, please update to latest parse-server version and reopen if the issue persist.

Don't forget to include your current:

  • node version
  • npm version
  • parse-server version
  • any relevant logs (VERBOSE=1 will enable verbose logging)

flovilmart avatar Jul 13 '16 00:07 flovilmart

hello I have a problem in the logout issue.After the logging out the parse current user I have intented to other activity but it is logging out the user and displaying the same activity and after the backpress it is moving to the login activity. if(item.getItemId() == R.id.logout){

        Intent BroadcastIntent = new Intent();
        BroadcastIntent.setAction("com.package.ACTION_LOGOUT");
        sendBroadcast(BroadcastIntent);
        Intent x = new Intent(UserListActivity.this,MainActivity.class);
        startActivity(x);
        finish();
        ParseUser.logOut();

    }

anjansrivathsav avatar Aug 04 '17 15:08 anjansrivathsav