Skip to content

Bring Your Own Login

Parse is already the easiest way to log in your users with Facebook, Twitter, or username and password, but, here at Parse, we're always trying to expand what developers can build on the platform. That's why we just launched some new methods to help you implement your own login schemes.

Building upon my previous post, Validating Session Tokens with the REST API, we've now added methods to the client SDKs for setting the current user based on a valid session token.

If you've created your own authentication routines, or otherwise logged in a user on the server side, you can now pass the session token to the client and use the 'become' method. This method will call back to Parse to validate the session token and fetch the associated user, then set the current user on the client.

Examples for iOS:

[PFUser becomeInBackground:@"session-token-here" block:^(PFUser *user, NSError *error) {
  if (error) {
    // The token could not be validated.
  } else {
    // The current user is now set to user.
  }
}];

Android:

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.
    }
  }
});

JavaScript:

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.
});

.NET:

try
{
  await ParseUser.becomeAsync("session-token-here");
  // The current user is now set to user.
}
catch (Exception e)
{
  // The token could not be validated.
}

This should open up some new avenues for advanced Parse developers!