i did the migration process for using the parse platform locally. i have deployed the parse-server-example on my localhost and hosted the DB on mongolab. First step is i am trying to register the user using the local parse server and on the DB instance hosted on mongolab.
This is the index.js of locally deployed parse server, and the following is the code snippet for android.
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
Stetho.initializeWithDefaults(this);
// Add your initialization code here
//Parse.initialize(this);
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("my app id")
.clientKey("my client key")
.server("http://10.12.41.250:1337/parse/") // '/' important after 'parse'
.addNetworkInterceptor(new ParseStethoInterceptor())
.build());
....
....
final ParseUser parseUser = new ParseUser();
parseUser.setUsername(edtUsername.getText().toString());
parseUser.setPassword(edtPassword.getText().toString());
parseUser.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(SignUpActivity.this, "You are now registered.", Toast.LENGTH_SHORT).show();
//Success
} else {
Toast.makeText(SignUpActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(TAG, e.getMessage());
//Failure
}
}
});
Upon executing this i am getting ParseRequestException with error message "this authentication method is unsupported", now i don't know what is it about and only thing that i found so far is This.
The following is the detail of network interceptor.
Any kind of help would be greatly appreciated.
So, That was an issue and it's Fixed now.
On my internship I must work with Parse.
I'm made now an android app in wich I am using this Parse Cloud.
I create a sign up button and if the user push this button, a new account should be create.
But after the pushing this button,I have this exception:
com.parse.ParseRequest$ParseRequestException: invalid session token
I don't know my mistake.Android Studio don't show any errors and I am using this instruction.
My app was work fine yesterday morning and my first app that I am created for 1 week ago have now the same problem.
I have internet connection and restarted my tablet device.
My source code:
ParseUser user = new ParseUser();
user.setUsername(username); // String username = "Ivan"
user.setPassword(password); // String password = "Divan"
user.enableRevocableSessionInBackground();
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Toast.makeText(getApplicationContext(),
"Successfully Signed up, please log in.",
Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getApplicationContext(),
"Sign up Error :" +e.toString(),
Toast.LENGTH_LONG).show();
}
}
});
Thanks and sorry for my bad english.
If you aren't using the latest version this tutorial explain how to make a migration. Also check the versions for all the sdk you are using.
I use a Parse database. I would like to have access for simple users and an admin user. The would be that each user could see only his/her own data but the admin user could see all of users' data.
I create a ParseUser, and if the current user is equal with it, it should be known it is the admin user.
I get the following error:
java.lang.IllegalArgumentException: cannot setReadAccess for a user with null id
I think the mistakes are with if function (never become true) and this: acl.setReadAccess(ADMIN,true);
Could anyone suggest something?
ParseUser ADMIN = new ParseUser();
ADMIN.setUsername("ADMIN3");
ADMIN.setPassword("a");
// Create a post.
AnywallPost post = new AnywallPost();
// Set the location to the current user's location
post.setLocation(geoPoint);
post.setText(text);
post.setUser(ParseUser.getCurrentUser());
ParseACL acl = new ParseACL();
// Give read accesses
if (ParseUser.getCurrentUser() == ADMIN) {
acl.setReadAccess(ParseUser.getCurrentUser(), true);
}
else
{
acl.setReadAccess(ParseUser.getCurrentUser(),true);
acl.setReadAccess(ADMIN,true);
}
post.setACL(acl);
// Save the post
post.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
dialog.dismiss();
finish();
}
});
I've been using Parse for 3 months in my android app. Now I want to add email login and social sign ons (Facebook and Google+) in the app. I have successfully added email and fb login and the user can connect both or either one of email or facebook and the app would recognise the user.
e.g. If I login through email, then connect facebook, use the app on another device, login via facebook, the app would know it's the same user and would be customised for me and would show my data. And email also works.
I have added Google+ sign-in for Android but I am not able to connect the user's Google+ credentials with the logged in user.
Parse Users table has an authData field which gets the facebook auth data and would get Twitter as well as both of these sign ons are baked into Parse SDKs.
What should be the best thing to do for Google+? I'm confused about the db design as well as how to connect the user who signed in with Google+?
What if the user just logs in via Google+? How do I make a Parse User and authenticate the user on Parse?
I'm comfortable with cloud code and Android and would really appreciate some sort of help/instructions just pushing me in the correct direction. I have never used OAuth2 and with Parse login for email and Social Sign ons, I don't think I should get into it. But let me know if I'm wrong.
Thanks!
Update: I have read a lot of questions on Parse Questions and have checked out the become method plenty of times (because I kept thinking I'm missing something after reading that). Check this question - I'm currently in the same situation.
I have:
1. Implemented Google+ sign in.
2. Got access token using GoogltAuthUtil.
Stuck with:
3. How to link currently signed in Parse user after the user signs in with Google+?
4. How to create a new Parse User if Google+ was the user's first (and only ) login choice?
This seems to be similar with
How to create a parse _User account from a Android Google token?
Following is my answer in that thread:
1. New User
The flow is as below:
User authorizes and a token is acquired
We create a new user with a random password
You can create a ParseUser using following code inside the newChooseAccountIntent() method that return email.
ParseUser user = new ParseUser();
user.setUsername(mEmail);
user.setPassword(randomPassword);
user.setEmail(mEmail);
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
2. Returning User
This is the where most of people stuck, as I researched over the Internet. The flow is as below:
User authorizes and the app gets a token
We pass this token to Cloud Code to validate. We need to check if this token is signed by Google and if it is meant for us (android-developers (2013)).
After you can verify that the token is valid, you can query for the user in Cloud Code using Parse.Cloud.useMasterKey() method and return the session key by using getSessionToken() method on the query result.
Use the session key to save login state on disk by calling becomeInBackground method
To validate the token, you can send Parse.Cloud.httprequest to this endpoint: https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=. This is instructed in Google Identity Documentation. You will receive data as below:
{
"iss": "https://accounts.google.com",
"sub": "110169484474386276334",
"azp": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
"email": "billd1600#gmail.com",
"at_hash": "X_B3Z3Fi4udZ2mf75RWo3w",
"email_verified": "true",
"aud": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
"iat": "1433978353",
"exp": "1433981953"
}
Things need to compare are "aud", "azp" and "email" which are translated as audience, authorized party and email.
To query for the current user on Cloud Code:
var query = new Parse.Query(Parse.User);
query.equalTo("email",mEmail);
query.first({
success: function(user) {
// Use user..getSessionToken() to get a session token
},
error: function(user, error) {
//
},
useMasterKey: true
});
Note: Make sure you have following scope so that the email will show up when you check on Cloud Code: https://www.googleapis.com/auth/plus.profile.emails.read
There's a question about this on Parse's questions. It's right here and I'm pretty sure it answers your questions.
https://parse.com/questions/google-plus
It links to the parse blog, that has some workarounds on this.
It says that you can add any login into ParseUser. You would be doing something like this:
Parse.User.become("session-token-here").then(function (user) {
// The current user is now set to user.
}, function (error) {
// The token could not be validated.
});
Another site where you should take a look:
https://parse.com/tutorials/adding-third-party-authentication-to-your-web-app
This last one is official and has an example code
void createNewGPlusUser(final String email, String name) {
final ParseUser user = new ParseUser();
user.setUsername(email);
user.setPassword("my pass");
user.put("any other variable in User class", "value");
user.setEmail(email);
user.put("name", name);
signInParseUser(user, email);
}
void signInParseUser(final ParseUser user, final String email) {
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Log.d("TAG", "Created user");
// Hooray! Let them use the app now.
login(email);
} else {
Log.d("TAG", "Failed Creating user");
e.printStackTrace();
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
}
void login(final String email) {
ParseUser.logInInBackground(email, "my pass", new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// Hooray! The user is logged in.
Log.d("TAG", "Login successful");
} else {
// Signup failed. Look at the ParseException to see what happened.
}
}
});
}
To do so, I have used the following code
ParseUser.becomeInBackground(ParseUser.getCurrentUser().getSessionToken(), new LogInCallback() {
#Override
public void done(ParseUser parseUser, ParseException e) {
if (parseUser != null) {
parseUser.setUsername(userEmail);
//firstName and lastName I am getting from Person class of google plus api
parseUser.put("FirstName", firstName);
parseUser.put("LastName", lastName);
parseUser.saveInBackground();
ParseUtils.verifyParseConfiguration(context);
ParseUtils.subscribeWithUsername(strEmail);
Intent successIntent = new Intent(context, OurServicesActivity.class);
startActivity(successIntent);
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
finish();
} else {
Log.e(TAG, e.getMessage());
Utilities.showToast(context, "Something occurred");
}
}
});
Let me know if it helps or if you have used something else.
Try this
ParseUser.becomeInBackground("session-token-here", new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// The current user is now set to user.
} else {
// The token could not be validated.
}
}
})
I am developing android application and using parse.com as back end storage. But I got stuck on change password. I am able to send the reset password mail using parse.com sdk to particular email. but I want to change the password using application as well without log enter code herein using old password.
Function to send mail:-
public void resetPassword() {
CustomProgressDialog.show(LoginActivity.this, "", getResources()
.getString(R.string.please_wait));
ParseUser.requestPasswordResetInBackground("test#gmail.com",
new RequestPasswordResetCallback() {
public void done(ParseException e) {
CustomProgressDialog.dismissMe();
if (e == null) {
// An email was successfully sent with reset
// instructions.
Toast.makeText(getApplicationContext(), getResources().getString(R.string.reset_password_sent), Toast.LENGTH_LONG).show();
} else {
// Something went wrong. Look at the ParseException
// to see what's up.
Toast.makeText(getApplicationContext(), getResources().getString(R.string.reset_password_fail), Toast.LENGTH_LONG).show();
}
}
}
);
}
And also able to launch the application from mail using declaring the permission in AndroidManifest.xml.
You can use for that next method ParseUser.setPassword().
Idea is next, if user is logged in then you don't need to check old password, because it was already entered and applied by Parse.com. So you will have 2 fields New Password and Confirm New Password. Users enters them and application changes it on server.
ParseUser parseUser = ParseUser.getCurrentUser();
parseUser.setPassword(password);
parseUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (null == e) {
// report about success
} else {
// report about error
}
}
});