Permissions for a new user / Parse-server-Heroku - objective-c

I just created a new user on parse-server/Heroku. Using code like this:
PFUser *x = [[PFUser alloc] init];
x.username = #"XXX";
x.password = #"yyyy";
x.email = #"email123#abc.com";
[x signUpInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if (succeeded) {
NSLog(#"kensu registration ALL OK!!!!");
} else if (error) {
NSLog(#"kensu registration error: %#",error);
}
}];
The user creation went fine. And I can log in witn this new user.
The problem comes after.
When I log in with the new user, I am not allowed to make any update on my mongoDB.
I get this kind of error message:
[Error]: Permission denied for action update on class ....
If I log with the unique user I had before, I can update without any problem. Why?
I looked at the user collection to see any difference, then tried a few things, but without success.
I hope someone can point me in the right direction.

Related

OSX ACAccountStore requestAccessToAccountsWithType... returning 'granted=No' and error=nil after denying permissions

I am trying to request access to my facebook account. The first time I ran this it went well and I saw the popup requesting permissions. The popup asked me to allow or deny. I chose to deny because I wanted to test that use case. Now I cannot figure out how to get it to allow access again. I have deleted the app from my facebook account and deleted my facebook account from my mac. I've also tried adding the property
#"auth_type": #"rerequest"
to the options dictionary. I get the same result no matter what.
As mentioned in the title, the error is nil and granted is False.
Thanks in advance.
ACAccountType* accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary* options = #{
ACFacebookAppIdKey: [[NSBundle mainBundle] objectForInfoDictionaryKey:#"FacebookAppID"],
ACFacebookPermissionsKey: #[#"public_profile", #"email", #"user_friends"],
};
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError* error)
{
if (granted)
{
ACAccount* account = [[accountStore accountsWithAccountType:accountType] lastObject];
macFacebookAccount = account;
}
else
{
NSLog(#"%#", error);
}
}];
I solved this: Facebook permission settings for an app are located under System Preferences > Security and Privacy. From there just click facebook and check the box next to your app

I want to create a ViewController where user can change there existing password. I m using Parse API

PFUser *user = [PFUser currentUser];
// I can see the details of the users when this is called including password
if (user) {
if ([_login_txtpassword.text isEqualToString:user[#"UserPasswrod"]]) {
user[#"userPassword"] = _login_txtnewpassword.text;
[user saveInBackground];
NSLog(#"done");
}
}
this code is not working.... i have put blocks to test my code ... it doesnt pass the if statement
A little conflict in my concepts related parse (so consider me as a noob)
P.S i have read the documentation and search internet but couldnt find a solution.
Many Many thanks in advcance
The right way to do this is to try to log the user in with the old password, then set the new password if successful. (notice this code uses the parse User password attribute, not #"userPassword" as in the OP code, which won't work under any circumstances)...
NSString *username = [PFUser currentUser].username;
NSString *oldPassword = self.oldPasswordTextField.text;
NSString *newPassword = self.newPasswordTextField.text;
[PFUser logInWithUsernameInBackground:username password:oldPassword
block:^(PFUser *user, NSError *error) {
if (user) {
user.password = newPassword;
[user saveInBackground];
} else {
// update UI to tell user that the old password is incorrect
}
}];
Actually you can't override the password of the current user directly from your ViewController. The user should request a new password, that will by sent to his/her email by Parse.
PFUser *currentUser = [PFUser currentUser];
NSString *userEmail = [NSString stringWithFormat: #"%#", currentUser.email];
[PFUser requestPasswordResetForEmailInBackground:userEmail];
or
[PFUser requestPasswordResetForEmailInBackground:self.userEmailTextfield.text];

Saving user causes object not found error

Saving a user causes Error: object not found for update (Code: 101, Version: 1.2.19)
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
if (!error) {
[PFUser currentUser].location = geoPoint;
[[PFUser currentUser] save];
}
}];
what am I doing wrong?
http post request https://api.parse.com/2/update
{
"iid": "[redacted]",
"classname": "_User",
"data": {
"email": "test#test.com",
"objectId": "[redacted]"
},
"session_token": "[redacted]",
"v": "i1.2.19",
"uuid": "[redacted]"
}
response
{
"code": 101,
"error": "object not found for update"
}
I have the same problem as you, I done some testing and figure out root cause:
Create new class GameScore as document
Do the same create and update object and find out it works well
Check the "ACL" columns and compare to your problem data. See?
Works ACL, I done modify for * to make it clear
Failed ACL.
As you could see the write privilege lock to user "6iIv5XWZvM", that's why your update will "not found object"
You could change data record directly to "*" to let your update works well.
OK! Here is solution as follow:
Change every record "ACL" data col as follow:
{"*":{"write":true,"read":true}}
You need login PFUSer as specific user to change ACL to public. For my case use objectId will be "6iIv5XWZvM". I need set password and login info and use code to login and modify it. Detail iOS code as follow:
//iOS Sample
[PFUser logInWithUsernameInBackground:#"USERNAME" password:#"PASSWORD" block:^(PFUser *user, NSError *error) {
if (user) {
PFQuery *query = [PFQuery queryWithClassName:CLASS_NAME];
[query findObjectsInBackgroundWithBlock:^(NSArray *objs, NSError *error) {
for (PFObject *obj in objs) {
PFACL *defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[defaultACL setPublicWriteAccess:YES];
[obj setACL:defaultACL];
[obj saveInBackground];
}
}];
} else {
// The login failed. Check error to see why.
}
}];
However remember to add following setting before you save new data, if you don't want to happen anymore (note: it will be security concern)
//It is iOS code sample.
PFACL *defaultACL = [PFACL ACL];
[defaultACL setPublicReadAccess:YES];
[defaultACL setPublicWriteAccess:YES];
[PFACL setDefaultACL:defaultACL withAccessForCurrentUser:YES];
Try this, i'm using this, when i need to save objects for the current user. Hope it will help.
PFUser *user = [PFUser currentUser];
[user setObject:geoPoint forKey:#"location"];
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(#"Error %# %#", error, [error userInfo]);
}
}];
The error : "object not found for update" append when the you try to save an object that the user does not have ACL access.
In order to let the user change the object you need to set PFACL permission when you create the object :
For a specific user :
PFObject *object = /*the object you want to save*/
NSString *userID = /*the objectID of the user you want to let perform modifications later*/
PFACL *groupACL = [PFACL ACL];
[groupACL setWriteAccess:YES forUserId:userID];
object.ACL = groupACL;
For a all users :
PFObject *object = /*the object you want to save*/
NSString *userID = /*the objectID of the user you want to let perform modifications later*/
PFACL *groupACL = [PFACL ACL];
[groupACL setPublicWriteAccess:YES];
object.ACL = groupACL;

Check if Authenticated User Likes A Certain Page (Using SLRequest)?

I've been looking through the open grpah reference docs, and can't seem to find a good example related to SLRequest regarding users and whether they like a certain page or not. I don't want to iterate through their entire list of likes.
I was looking at https://developers.facebook.com/docs/graph-api/reference/user/likes/ but I'm not sure how to work with it and SLRequest, I've done the following but I'm receiving the following response:
Received Response: {"error":{"message":"An active access token must be used to query
information about the current
user.","type":"OAuthException","code":2500}}
Thing is all of this code only runs if the suer has previously authenticated and granted permission, and so it must have found an account, yet I still get this respond. Could it be that I'm not requesting a specific permission? I've requested, "email, public_actions, user_likes and public_stream".
BTW I do have another view controller where I ask for these permissions (except user_likes), and everything works in that one. Is there anything that I'm missing here? Thanks!
NSURL *feedURL = [NSURL URLWithString:#"https://graph.facebook.com/me/likes/{MYPAGEID}"];
[SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:feedURL parameters:nil];
[updateFeedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (responseData ) {
NSLog(#"Received Response: %#", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {
NSLog(#"Successful Connection");
} else {
}
} else {
NSLog(#"No response.");
}
}];
The error that you are getting is received when you try to make calls like /me but no user is currently logged-in to your app or the user has already logged-out of the app.
I'm not sure of your complete flow of the app but you can try this to validate your access token and call- you have the access token right? so, with your current API call just add an extra parameter access_token with its value.

How to make IOS ask to grant permissions to access user accounts

[self.ACAstore requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) {
self.bPermissionToAccessStoreGranted=granted;
[self vContinue];
// Handle any error state here as you wish
}];
The result of granted is simply false. I want users to get get asked first.
The possible cause is that the iPhone has no twitter accounts. In which case I want to display a twitter login page so user can sign up.
[self.ACAstore requestAccessToAccountsWithType:twitterType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted)
{
[self vContinue];
}
else {
// Handle any error state here as you wish
}
}];
Do you want this?