Parse-server: Unable to save Anonymous user

Created on 28 Mar 2016  Â·  12Comments  Â·  Source: parse-community/parse-server

Setup parse-server on AWS, and passed the CRUD transactions successfully. In my app which is working with parse.com, i switched to my hosted parse-server and it fails when trying the save anonymous user. Even the simple query fails. See codes below:

Environment Setup

> iOS SDK: 1.12.0
> hosted on AWS with the following package.son file:

 {
  "name": "parse-server-example",
   "version": "1.3.0",
   "description": "An example Parse API server using the parse-server module",
   "main": "index.js",
   "repository": {
     "type": "git",
     "url": "https://github.com/ParsePlatform/parse-server-example"
   },
   "license": "MIT",
   "dependencies": {
     "express": "~4.11.x",
     "kerberos": "~0.0.x",
     "parse": "~1.6.12",
     "parse-server": "~2.1.6"
   },
   "scripts": {
     "start": "node index.js"
   },
   "engines": {
     "node": ">=4.3"
   }
 }

Steps to reproduce when saving current user

    // save the new anonymous user
    if ([PFUser currentUser].isDirty) {
        [[PFUser currentUser] saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (error) {
                DLog(@"Anonymous login failed.");
            } else {
                DLog(@"Anonymous user logged in.");
            }
        }];

Logs/Trace

[Error]: unauthorized (Code: 0, Version: 1.12.0)
[AppDelegate syncWithCloud]_block_invoke [Line 681] Anonymous login failed.

Steps to reproduce when query a class

+ (void) queryEvents {
    DLog(@" *** QueryEvents started...");
    PFQuery *query = [PFQuery queryWithClassName:kParseClassEvent];
    [query orderByDescending:@"status,name"];
    query.limit = 500;  // By default, results are limited to 100, but anything from 1 to 1000 is a valid limit:
    query.cachePolicy = kPFCachePolicyNetworkElseCache;

    // Run the query
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            DLog(@"**** query results count: %lu", (unsigned long)objects.count);
            [[NSNotificationCenter defaultCenter] postNotificationName:kQueryEventsDidFinishNotification object:objects];
        }
        else { // something bad happened
            DLog(@"**** something bad happened %ld:%@", (long)error.code ,error.description);
            [[NSNotificationCenter defaultCenter] postNotificationName:KQueryEventsDidFailNotification object:error];
        }
    }];
    DLog(@" *** QueryEvents ended ...");
}

Logs/Trace

[ParseUtil queryEvents]_block_invoke [Line 262] ** something bad happened 120:Error Domain=Parse Code=120 "Cache miss." UserInfo={error=Cache miss., NSLocalizedDescription=Cache miss., code=120}

Most helpful comment

we'll have a look some time, I refactored at one point the key checking algorithm a while ago but I can't seem to remember what the expected behaviour is. If you pass a client key and the server don't have one, maybe the server should let is pass, maybe not... I'm lost. Glad it fixed it.

All 12 comments

Can you update your package.json to reference version 2.2.2 of parse-server, npm install and try again, and check the server logs for more information?

Thanks for your reply.
I updated to 2.2.2 of parse-server and got the same error.
With the new added [Parse initializeWithConfiguration:], I had to get rid of the old code [Parse setApplicationId:]. Commenting that fixed the issue for the query events.
Note: It seems with latest iOS SDK, initializeWithConfiguration method still needs clientKey. Something that should be optional.

// Point Client to aws Parse Server, at least version 1.12 for iOS is required.
    [Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
        configuration.applicationId = kParseAppId;
        configuration.clientKey = kParseClientKey;
        configuration.server = kParseServer;
 }]];

// No need to keep this line anymore
// [Parse setApplicationId:kParseAppId clientKey:kParseClientKey];

The anonymous login still fails with error:

Failed to run command eventually with error: Error Domain=Parse Code=0 "unauthorized" UserInfo={error=unauthorized, NSLocalizedDescription=unauthorized, temporary=0}

I deleted the app and re-installed it with clean cache. Same error!
Checked the AWS server log, and couldn't find anything specific to this error. Should say I am not that familiar with AWS logging mechanism. Seems there is a way to log the request/response using Lambda but not there yet.

Did you set the client key on when initializing parse-server?

No. Just appID and masterKey.
Do I need to?

On Mar 29, 2016, at 9:38 AM, Florent Vilmart [email protected] wrote:

Did you set the client key on when initializing parse-server?

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub

Yeah most likely as you,re sending it from the client I'm not sure parse-server likes it :)

Sure, I give it a try when I get home.

On Mar 29, 2016, at 12:40 PM, Florent Vilmart [email protected] wrote:

Yeah most likely as you,re sending it from the client I'm not sure parse-server likes it :)

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub

In my opinion, no client keys should be set on the server (Rest, client, windows, js), and then no client keys are required from the clients (even though you can set/send them.) If any are set on the server, then all requests require them. You will figure this out. Unauthorized means you're not using the right combination of server / appId or there's a client key set and it doesn't match.

I just followed the document, which says no client key is required, and I didn't set the clientKey on the server side.
The problem is iOS SDK won't let you to pass null for client key, therefore it seems it would be a must-have key on the server side, which doesn't make sense!
I will test it this afternoon and report back.

On Mar 29, 2016, at 1:01 PM, Fosco Marotto [email protected] wrote:

In my opinion, no client keys should be set on the server (Rest, client, windows, js), and then no client keys are required from the clients (even though you can set/send them.) If any are set on the server, then all requests require them. You will figure this out. Unauthorized means you're not using the right combination of server / appId or there's a client key set and it doesn't match.

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub

Also, wondering why I get a successful query response back from server, but unable to save anonymous user?
If key combination is wrong, shouldn't both be rejected as unauthorized?

On Mar 29, 2016, at 1:01 PM, Fosco Marotto [email protected] wrote:

In my opinion, no client keys should be set on the server (Rest, client, windows, js), and then no client keys are required from the clients (even though you can set/send them.) If any are set on the server, then all requests require them. You will figure this out. Unauthorized means you're not using the right combination of server / appId or there's a client key set and it doesn't match.

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub

The client can send a key, and the server will ignore it... As for the save
issue, that's why you'll need to do some more troubleshooting/logging to
pinpoint the issue.

On Tuesday, March 29, 2016, Mike [email protected] wrote:

Also, wondering why I get a successful query response back from server,
but unable to save anonymous user?
If key combination is wrong, shouldn't both be rejected as unauthorized?

On Mar 29, 2016, at 1:01 PM, Fosco Marotto <[email protected]

In my opinion, no client keys should be set on the server (Rest, client,
windows, js), and then no client keys are required from the clients (even
though you can set/send them.) If any are set on the server, then all
requests require them. You will figure this out. Unauthorized means you're
not using the right combination of server / appId or there's a client key
set and it doesn't match.

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
https://github.com/ParsePlatform/parse-server/issues/1230#issuecomment-203042477

@flovilmart was right, parse-server didn't like it :) Adding the clientKey on the server side fixed the issue. It seems at least for iOS SDK 1.12.0 we need clientKey on the server side.
Seems like a bug to me!

we'll have a look some time, I refactored at one point the key checking algorithm a while ago but I can't seem to remember what the expected behaviour is. If you pass a client key and the server don't have one, maybe the server should let is pass, maybe not... I'm lost. Glad it fixed it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShawnBaek picture ShawnBaek  Â·  4Comments

jaydeep82 picture jaydeep82  Â·  4Comments

kilabyte picture kilabyte  Â·  4Comments

lorki picture lorki  Â·  3Comments

darkprgrmmr picture darkprgrmmr  Â·  4Comments