Skip to content

Unable to save Anonymous user #1230

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

Closed
Jinoooo opened this issue Mar 28, 2016 · 12 comments
Closed

Unable to save Anonymous user #1230

Jinoooo opened this issue Mar 28, 2016 · 12 comments

Comments

@Jinoooo
Copy link

Jinoooo commented Mar 28, 2016

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

[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}

@gfosco
Copy link
Contributor

gfosco commented Mar 28, 2016

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?

@Jinoooo
Copy link
Author

Jinoooo commented Mar 29, 2016

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.

@Jinoooo Jinoooo closed this as completed Mar 29, 2016
@Jinoooo Jinoooo reopened this Mar 29, 2016
@flovilmart
Copy link
Contributor

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

@Jinoooo
Copy link
Author

Jinoooo commented Mar 29, 2016

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

@flovilmart
Copy link
Contributor

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

@Jinoooo
Copy link
Author

Jinoooo commented Mar 29, 2016

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

@gfosco
Copy link
Contributor

gfosco commented Mar 29, 2016

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.

@gfosco gfosco closed this as completed Mar 29, 2016
@Jinoooo
Copy link
Author

Jinoooo commented Mar 29, 2016

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

@Jinoooo
Copy link
Author

Jinoooo commented Mar 29, 2016

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

@gfosco
Copy link
Contributor

gfosco commented Mar 29, 2016

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]
javascript:_e(%7B%7D,'cvml','[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


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
#1230 (comment)

@Jinoooo
Copy link
Author

Jinoooo commented Mar 30, 2016

@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!

@flovilmart
Copy link
Contributor

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.

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

3 participants