Description
Hi, so I used the anyPhone example here for logging in with Twilio, https://github.com/ParsePlatform/AnyPhone
The problem is, on Android, when we get the session token back from the cloud code and try on Android Parseuser.becomeinbackground(token, callback);
The error that we get is com.parse.ParseRequest$ParseRequestException: bad json response
I checked and debugged and saw that the session token is the same session token i have in the database, they are totally the same.
The funny thing is, this worked on Api.parse.com but not on our hosted parse server.
So i am wondering if this is a parse function bug or a bug in the sdk.
Steps to reproduce
Please include a detailed list of steps that reproduce the issue. Include curl commands when applicable.
- Use AnyPhone example on github, log in to the app with phone number
- Use the cloud function "logIn"
Parse.Cloud.define("logIn", function(req, res) {
var phoneNumber = req.params.phoneNumber;
phoneNumber = phoneNumber.replace(/\D/g, '');
if (phoneNumber && req.params.codeEntry) {
Parse.User.logIn(phoneNumber, secretPasswordToken + req.params.codeEntry).then(function (user) {
console.log(user.getSessionToken());
res.success(user.getSessionToken());
}, function (err) {
res.error(err);
});
} else {
res.error('Invalid parameters.');
}
});
It sends back the user session token to android
3. It comes back to android and the user puts the code that was sent via twilio
and this function gets called
private void doLogin() {
if (mInputText.getText().toString().isEmpty() || mInputText.getText().toString().length
() != 4) {
mInputText.setError("4 digits only");
codeUI();
}
else {
int code = Integer.parseInt(mInputText.getText().toString());
HashMap<String, Object> params = new HashMap<>();
params.put("phoneNumber", phoneNumber);
params.put("codeEntry", code);
ParseCloud.callFunctionInBackground("logIn", params, new FunctionCallback<String>() {
public void done(String response, ParseException e) {
if (e == null)
{
Log.d(TAG, "It called this function");
Log.d (TAG, response);
mToken = response;
Log.d ("Cloud Response", "There were no exceptions! " + response);
ParseUser.becomeInBackground(mToken, new LogInCallback()
{
@Override
public void done(ParseUser parseUser, ParseException e) {
if (parseUser != null)
{
Log.d(TAG,"become in background worked");
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", parseUser);
installation.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
Intent intent = new Intent(SignupActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
});
}
else
{
Log.d(TAG, "parse become in background did not work");
Log.d(TAG, "No response was given");
Log.d("Cloud Response", "Exception: " + e.toString());
Toast.makeText(getApplicationContext(),
"Something went wrong. Please try again." + e.toString(),
Toast.LENGTH_LONG).show();
phoneNumberUI();
}
}
});
}
else
{
phoneNumberUI();
Log.d("Cloud Response", "Exception: " + response + e);
Toast.makeText(getApplicationContext(),
"Something went wrong. Please try again.",
Toast.LENGTH_LONG).show();
}
}
});
}
}
It fails at Parseuser.BecomeinBackground, due to the token being a bad json response.
Expected Results
It should run the becomeinbackground and log the user into the app
Actual Outcome
com.parse.ParseRequest$ParseRequestException: bad json response
Environment Setup
- Server
- parse-server version: [2.2.16]
- Operating System: [64bit Amazon Linux 2016.03 v2.1.3 running Node.js]
- Hardware: [N/A]
- Localhost or remote server? (AWS)
- Database
- MongoDB version: [2.6]
- Storage engine: [Sandbox]
- Hardware: [Single database
on multi-tenanted process] - Localhost or remote server? (mLab)
I wonder is it a problem with the Parse Server the function Parse.User.login or is it a problem with the android code, ParseUser.become.
I am not so good with server or database stuff, as i am more android side of things. I will provide as much as I can.