Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PFKeychainStore failed to set object for key 'currentUser', with error: -34018 #437

Closed
a1exb1 opened this issue Oct 19, 2015 · 124 comments
Closed

Comments

@a1exb1
Copy link

a1exb1 commented Oct 19, 2015

User is authenticated with facebook.

sometimes when i try to do a fb request:

let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me/friends", parameters: nil)
graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

it spams:
PFKeychainStore failed to set object for key 'currentUser', with error: -34018
in the console.

@nlutsenko
Copy link
Contributor

Hey @a1exb1, this sounds super weird.
The error is coming down from our keychain storage for authData/sessionToken for currentUser, since that information should be private.

Any chance you can get us more context on when it happens and/or more data about the state of currentUser when the problem happens?

@parse-github-bot
Copy link

Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.

Please try the latest SDK. Our release notes have details about what issues were fixed in each release.

In addition, you might find the following resources helpful:

@horseshoe7
Copy link

I also get this issue periodically and it's hard to tell what causes it. It just seems like it can randomly occur. I'm finding debugging the Parse SDK to be indeed very difficult because you can't trace back to the calling context due to all the BFTasks in between, etc.

I'm using a pretty recent SDK, since I only started working with Parse 1-2 weeks ago.

@Perjan
Copy link

Perjan commented Oct 30, 2015

The same for me. I have tried it in two apps, one with FB authentication and one without.
Both fire this error log. You have to hard close the app and rerun it again, so you can hope to get logged in.

This bug is killing me, because one time appears, and one time it doesn't. And I am using the latest SDK.
@nlutsenko We need your magic touch :).

@horseshoe7
Copy link

yes, seriously. This has basically torpedoed my client’s project.

Can we get any insight into why it happens??

On Friday 30 October 2015 at 09:55, Perjan Duro wrote:

The same for me. I have tried it in two apps, one with FB authentication and one without.
Both fire this error log. You have to hard close the app and rerun it again, so you can hope to get logged in.
This bug is killing me, because one time appears, and one time it doesn't. And I am using the latest SDK.
@nlutsenko (https://github.com/nlutsenko) We need your magic touch :).


Reply to this email directly or view it on GitHub (#437 (comment)).

@Perjan
Copy link

Perjan commented Oct 30, 2015

Just right now I got this error, when I tried to edit a property in a PFUser logged from a FB account.

[Error]: Caught "NSInternalInconsistencyException" with reason "User cannot be saved unless they have been authenticated via logIn or signUp":

@horseshoe7
Copy link

For me it just continues to carry on working, but I’m unsure as to what’s happened. I don’t get invalid session token errors or anything like that.

On Friday 30 October 2015 at 10:48, Perjan Duro wrote:

Just right now I got this error, when I tried to edit a property in a PFUser logged from a FB account.
[Error]: Caught "NSInternalInconsistencyException" with reason "User cannot be saved unless they have been authenticated via logIn or signUp":


Reply to this email directly or view it on GitHub (#437 (comment)).

@horseshoe7
Copy link

I updated to Parse v 1.9.1 . So far so good...

@horseshoe7
Copy link

I have seen this again, but I'm wondering if it's because it's an async API and I had set a breakpoint. Anyhow, the problem is much less running 1.9.1 !!

@parse-github-bot
Copy link

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

@nlutsenko
Copy link
Contributor

Hey guys, I've looked further into this error, and it looks to be a bug in the Security framework itself.
It's been discussed and acknowledged by Apple here - https://forums.developer.apple.com/thread/4743#14441

Is anyone getting any other error except of -34018?

@vandutran
Copy link

I just got this error. On Parse 1.9.1 and Facebook 4.7.0.

I honestly don't know how to reproduce. Maybe a hint is that when I have crappy network connection..

[Error]: PFKeychainStore failed to get object for key 'currentUser', with error: -34018

@antoescu
Copy link

I am having the same error when logging in with Twitter, not every time. I am using Parse 1.9.1 and iOS 9.1

@brennanMKE
Copy link

This keeps happening with an app I am developing as well. It is preventing us from moving forward.

@nlutsenko
Copy link
Contributor

@brennanMKE How does this prevent you guys from proceeding?
Is there a change in behavior or say failing requests? Or simply an error logged to the console?

@brennanMKE
Copy link

@nlutsenko We are trying to get push notifications to work and I am trying to set values on the User instance so that Cloud Code can determine when a push will be triggered. Since I cannot set values on the User it prevents push notifications from being processed.

Either I get this error or UserCannotBeAlteredWithoutSessionError. I have the AppDelegate run PFUser.enableAutomaticUser() in application:didFinishLaunchingWithOptions: which should ensure that an anonymous user is created. Yet sometimes it is nil after it shows the error with the keychain. Then once I do get a user it is not possible to save the user because of the session.

@nlutsenko
Copy link
Contributor

Gotcha. @brennanMKE, any chance you can add a repro project that has this issue reproducible at least semi-consistently?

@brennanMKE
Copy link

@nlutsenko

I dug into it and found something which does not make sense to me. This is an iOS app built with Swift. I have been using PFUser.currentUser() after Parse is initialized and PFUser.enableAutomaticUser() is called. I am expecting that PFUser.currentUser() always returns a valid user but sometimes it returns a nil value.

So I called PFSession.getCurrentSessionInBackgroundWithBlock to get a session and checked session?.objectForKey("user") which does return a user but the objectId on that user does not match the user from PFUser.currentUser().

I expect that currentUser and currentSession would be synced up when enableAutomaticUser is used. What I am going to do next is a create a class in Swift called ParseSupport which will use blocks to return the Session and User objects and never use PFUser.currentUser() and instead always go through the Session. That approach may prevent these errors and allow for saving a user reliably.

Are my expectations accurate or am I not understanding how currentUser and currentSession should work?

@nlutsenko
Copy link
Contributor

That is super strange at this point... enableAutomaticUser() has a guarantee indeed that PFUser.currentUser() won't be nil, and it will create an empty unsaved user for you otherwise (won't save it automatically to Parse, but will create in-memory local one for sure).
session?["user"] should be set to PFUser.currentUser(), otherwise there is something funky going on with the sessionToken, meaning that the PFUser.currentUser().sessionToken belongs to a different user than the currentUser().

I am extremely curious to see the repro for this and fix/investigate further.

@brennanMKE
Copy link

I now get invalid session token when I try to save changes to the user. I am going delete and reinstall the app again. It's strange.

@brennanMKE
Copy link

After deleting and installing the app again it immediately shows the -34018 error.

PFKeychainStore failed to get object for key 'currentUser', with error: -34018

[Error]: invalid session token (Code: 209, Version: 1.9.1)

It is like the keychain is persisting data across app installs and I do not know a good way to do that on my device without doing a full reset like I can do with the iOS Simulator.

@nlutsenko
Copy link
Contributor

@brennanMKE Can you please attach a sample repro project? I will be more than glad to investigate, but simply can't repro it running on the device.

@brennanMKE
Copy link

There is nothing unusual in this app. In the AppDelegate in application:didFinishLaunchingWithOptions: Parse is configured like I have done many times. Then the code immediately tries to get the current user and save it to ensure that any other calls work later, such as saving the user with the PFInstallation object. I do not know if creating another project would recreate this problem. What I'd like to do is reset the keychain for the app but unfortunately deleting the app does not also remove keychain items related to the app so they seem to be there when the app is installed from Xcode later.

// Parse.enableLocalDatastore()
Parse.setApplicationId("appId", clientKey:"clientKey")
PFUser.enableAutomaticUser()

I have enabled the local database though not objects were pinned. I have since commented out that line.

@brennanMKE
Copy link

@nlutsenko What I am doing now is preparing some code in Swift which will log out the current values in the keychain so I can see what is in there. And once I can see the keychain items I will delete them. Maybe that will fix the problem.

I do not think it is the code. It is the persisting data in the keychain which is not being purged between installs.

@kshdeo
Copy link

kshdeo commented Nov 18, 2015

I have been facing this issue for last 2 weeks very consistently. It is easily reproducible as well. I just force a webview based authentication:

  [PFFacebookUtils setFacebookLoginBehavior:FBSessionLoginBehaviorForcingWebView];
  [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
      if (!user) {
           return;
      } else if (user.isNew) {
            FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"name, picture, email, gender, location, about, bio"}];
            [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
              NSLog(@"Error %@",error);
            }];
         }        
    }];

I first get the following error from above block:

    body =     {
         error =         {
              code = 2500;
              "fbtrace_id" = BNWEwNELi9T;
              message = "An active access token must be used to query information about the current user.";
              type = OAuthException;
          };
     };
   code = 400;

Then, it throws:
PFKeychainStore failed to get object for key 'currentUser', with error: -34018

I am using ParseFacebookUtils 1.9.1 and Parse 1.9.1, running on iOS 9.1

@nlutsenko
Copy link
Contributor

That error above ^^ looks like is coming from FBSDK not Parse.
I wonder if there is something weird going on in their field...

@kshdeo
Copy link

kshdeo commented Nov 18, 2015

@nlutsenko If it helps, [FBSDKAccessToken currentAccessToken] is nil on a new user signup in the logInWithPermissions: block. However, in my subsequent login attempts using the above method, there is no error. So, I was guessing it could be because current user is not linked with the FBAccessToken. I can provide more info if you want.

@nlutsenko
Copy link
Contributor

@kshdeo I would love to see the full repro project that I can repro this with, as any of the local testing that I am doing doesn't surface this issue in any way. If it's super private - you can send it to nlutsenko(at)fb.com

@flovilmart
Copy link
Contributor

That's highly probable.

@josepfm
Copy link

josepfm commented Oct 22, 2016

Puf.
Nobody try this?
I need a solution..

@flovilmart
Copy link
Contributor

When you enable keychain sharing in Xcode for your app target. Does it work?

@josepfm
Copy link

josepfm commented Oct 22, 2016

Because i do not have apple developer account, Xcode return when i enable keychain sharing:
captura de pantalla 2016-10-22 a las 18 37 48

@flovilmart
Copy link
Contributor

Is the entitlements file created? Can you confirm that it's still not working? You probably want to create a developper account anyway.

@josepfm
Copy link

josepfm commented Oct 22, 2016

I kill the app and delete all user in DataBase of Parse and when i try to edit a user and change few fields i can do it, but when i try to do it again, the problem return.

@josepfm
Copy link

josepfm commented Oct 22, 2016

Is this ?
captura de pantalla 2016-10-22 a las 18 41 13

Yes, of course i need a developer account but i want to be sure that this development will run and i will not have to change Parse for other solution like Firebase, for example.

I like Parse and i want to continue working with him.

@flovilmart
Copy link
Contributor

Yes that's the entitlements file, your issue would be resolved by having a full developer account. Starting iOS 10, I believe apple enforced more strongly keychain access from dynamically linked frameworks. Without the proper Keychain Sharing entitlements, it seems that the SDK is not correctly working.

@josepfm
Copy link

josepfm commented Oct 22, 2016

This is the content of the entitlements and the message of Xcode when i enable the keychain sharing:

captura de pantalla 2016-10-22 a las 18 45 31

captura de pantalla 2016-10-22 a las 18 46 06

@flovilmart
Copy link
Contributor

Yes and that should be solved if you have a proper developer account, and a properly configured Xcode.

@josepfm
Copy link

josepfm commented Oct 23, 2016

So i have to bet that the program will run when i will have an apple developer account?

Nobody happen this now?

It is not very professional betting by a project what don´t run now...

The only solution is apple developer account so?

Flovilmart, to you do not happens?

@mooshee
Copy link

mooshee commented Oct 23, 2016

It's happening to everyone who is building/running Parse on iOS 10. As Flovilmart outlined, the SDK stores the users' session information in the keychain. Apple changed the rules for 3rd party data to be read/write to the keychain. You must have an Apple Developer to enable keychain sharing.

You cannot release an app without an Apple Developer account. Many features (such as Push Notifications) require an account. To insinuate Parse, or it's community, is unprofessional for this reason is to also assume Apple is unprofessional. Perhaps Firebase would suit you better.

@josepfm
Copy link

josepfm commented Oct 24, 2016

Please, you don´t say things that i don´t say.

I am really charmed with Parse. My question is because i am doing a course about Parse and this problem don´t happen and i will want to know why, just this.

Of course i know that i can not release my app without Apple Developer account, only i will want to delay the moment of the payment for economic problems.

I don´t know why you attack me of this way but, you know.

Sorry if someone has been offended, it was not my intention.

@mooshee
Copy link

mooshee commented Oct 25, 2016

My statement still stands: Firebase may suit you better (if you have the option in your coursework). If you must build your app for iOS 10, then you will need a developer account or deal with an invalid session between every launch. Perhaps your class has not run into this issue because they are building / running on iOS 9 or prior.

Does that answer your question?

@KBog
Copy link

KBog commented Oct 25, 2016

I believe creating an Apple Developer account is FREE, you can now even test the app on the device without paying a dime. Once you're ready to release, then you'll need to pay.

@brennanMKE
Copy link

Yes, @KBog is right. You can see the chart at the bottom of the linked page below which shows that with an Apple ID you can create a developer account and deploy apps to a device. And if someone were to add you to their paid team it is possible you could have access to more functionality.

And schools can enroll in the iOS Developer University Program for free which could make several useful features available.

https://developer.apple.com/support/compare-memberships/

@josepfm
Copy link

josepfm commented Oct 28, 2016

Thanks @brennanMKE !

I tried my app in my device and it is so cool!

Regrettably to try the keychain storage i need an individual apple developer account, but for the moment i can try my app whit this.

When i will release my app, i will buy the individual apple developer account to try the keychain storage and test that my app run correctly and i can modify a PFUser.

@brennanMKE
Copy link

@jose46moreno You may want to duplicate your build target for your app so you can have a few app identifiers which each have their own keychain so that as you work you can manage them separately. I found that even deleting an app does not delete the associated keychain, so after installing the app again there are still remnants. I don't think that is correct behavior for iOS, but I've seen it happen. That's a bug which is beyond what the Parse SDK can handle.

@ericgiannini
Copy link

Updating a cell's nib with the method setImageForUserName like so [cell.profPic setImageForUserName:PFUser.currentUser.username]; returns a PFKeychainStore failed to set object for key 'currentUser', with error: -34018. Are there any suggestions about this particular method?

@mooshee
Copy link

mooshee commented Mar 28, 2017

@ericgiannini Have you already followed the steps above to enable keychain sharing? If not, you are likely see this type of error across the entire app every time you try to access a remote object that is protected by the user's session.

@ericgiannini
Copy link

Thanks, @mooshee! I will take the steps & update you. ;)

@tekmick
Copy link

tekmick commented Feb 4, 2019

Hi all.

I just started receiving this error:

PFKeychainStore failed to set object for key 'currentUser', with error: -25299

but only in the simulator. I am on Xcode 10.1, and an older version of the Parse SDK. I upgraded to the current version of the Parse SDK, and no difference. We have upgraded our Parse backend. Doesn't seem like that should have an effect on the front end though.

I've started following the chain back in this thread, but haven't come across anything yet. I do have a valid developer account, and am looking at the entitlement issues now.

I'm posting because the error number is different than what seems to run though this thread, so not sure if I have something different here.

If anyone has any info, please let me know, and I'll continue backtracking through this thread.

Thanks!

@flovilmart
Copy link
Contributor

@tekmick I encountered this thread that may be of interest: yankodimitrov/SwiftKeychain#13

Sent with GitHawk

@tekmick
Copy link

tekmick commented Feb 5, 2019

Ok, my bad. We have a couple of branches working on an upgrade of Parse for both back and front end. I was positive I was on the upgraded front end branch when I tested, but I wasn't. I am good here.

@tekmick
Copy link

tekmick commented Feb 5, 2019

flovilmart, thanks for the pointer!

@tekmick
Copy link

tekmick commented Feb 5, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests