public class Credentials extends Object
Logging into the Realm Object Server consists of the following steps:
Credentials object of the proper type e.g., facebook(String) for a
Facebook login.
User through the Object Server using these credentials. Once authenticated,
an Object Server user is returned. Then this user can be attached to a SyncConfiguration, which
will make it possible to synchronize data between the local and remote Realm.
It is possible to persist the user object e.g., using the UserStore. That means, logging
into an OAuth2 provider is only required the first time the app is used.
// Example
Credentials credentials = Credentials.facebook(getFacebookToken());
User.login(credentials, "http://objectserver.realm.io/auth", new User.Callback() {
\@Override
public void onSuccess(User user) {
// User is now authenticated and be be used to open Realms.
}
\@Override
public void onError(ObjectServerError error) {
}
});
| Modifier and Type | Class and Description |
|---|---|
static class |
Credentials.IdentityProvider
Enumeration of the different types of identity providers.
|
| Modifier and Type | Method and Description |
|---|---|
static Credentials |
custom(String identityProvider,
String userIdentifier,
Map<String,Object> userInfo)
Creates a custom set of credentials.
|
static Credentials |
facebook(String facebookToken)
Creates credentials based on a Facebook login.
|
String |
getIdentityProvider()
Returns the provider used by the Object Server to validate these credentials.
|
String |
getUserIdentifier()
Returns a String that identifies the user.
|
Map<String,Object> |
getUserInfo()
Returns any custom user information associated with this credential.
|
static Credentials |
google(String googleToken)
Creates credentials based on a Google login.
|
static Credentials |
twitter(String twitterToken)
Creates credentials based on a Twitter login.
|
static Credentials |
usernamePassword(String username,
String password,
boolean createUser)
Creates credentials based on a login with username and password.
|
public static Credentials usernamePassword(String username, String password, boolean createUser)
username - username of the user.password - the users password.createUser - true if the user should be created, false otherwise. It is not possible to
create a user twice when logging in, so this flag should only be set to true the first
time a users log in.User.loginAsync(Credentials, String, User.Callback).IllegalArgumentException - if user name is either null or empty.public static Credentials facebook(String facebookToken)
facebookToken - a facebook userIdentifier acquired by logging into Facebook.User.loginAsync(Credentials, String, User.Callback)IllegalArgumentException - if user name is either null or empty.public static Credentials google(String googleToken)
googleToken - a google userIdentifier acquired by logging into Google.User.loginAsync(Credentials, String, User.Callback)IllegalArgumentException - if user name is either null or empty.public static Credentials twitter(String twitterToken)
twitterToken - a google userIdentifier acquired by logging into Twitter.User.loginAsync(Credentials, String, User.Callback)IllegalArgumentException - if user name is either null or empty.public static Credentials custom(String identityProvider, String userIdentifier, Map<String,Object> userInfo)
identityProvider and
userInfo used.identityProvider - provider used to verify the credentials.userIdentifier - String identifying the user. Usually a username of userIdentifier.userInfo - data describing the user further or null if the user does not have any extra data. The
data will be serialized to JSON, so all values must be mappable to a valid JSON data type. Custom
classes will be converted using toString().User.loginAsync(Credentials, String, User.Callback).IllegalArgumentException - if any parameter is either null or empty.public String getIdentityProvider()
public String getUserIdentifier()
Credentials.IdentityProvider used.public Map<String,Object> getUserInfo()
Credentials.IdentityProvider
used.