public class SyncCredentials extends Object
Logging into the Realm Object Server consists of the following steps:
SyncCredentials
object of the proper type e.g., facebook(String)
for a
Facebook login.
SyncUser
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 |
SyncCredentials.IdentityProvider
Enumeration of the different types of identity providers.
|
Modifier and Type | Method and Description |
---|---|
static SyncCredentials |
accessToken(String accessToken,
String identifier)
Creates credentials from an existing access token.
|
static SyncCredentials |
custom(String userIdentifier,
String identityProvider,
Map<String,Object> userInfo)
Creates a custom set of credentials.
|
static SyncCredentials |
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 SyncCredentials |
google(String googleToken)
Creates credentials based on a Google login.
|
static SyncCredentials |
usernamePassword(String username,
String password)
Creates credentials based on a login with username and password.
|
static SyncCredentials |
usernamePassword(String username,
String password,
boolean createUser)
Creates credentials based on a login with username and password.
|
public static SyncCredentials facebook(String facebookToken)
facebookToken
- a facebook userIdentifier acquired by logging into Facebook.SyncUser.loginAsync(SyncCredentials, String, SyncUser.Callback)
.IllegalArgumentException
- if user name is either null
or empty.public static SyncCredentials google(String googleToken)
googleToken
- a google userIdentifier acquired by logging into Google.SyncUser.loginAsync(SyncCredentials, String, SyncUser.Callback)
.IllegalArgumentException
- if user name is either null
or empty.public static SyncCredentials 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.SyncUser.loginAsync(SyncCredentials, String, SyncUser.Callback)
.IllegalArgumentException
- if user name is either null
or empty.public static SyncCredentials usernamePassword(String username, String password)
username
- username of the user.password
- the users password.SyncUser.loginAsync(SyncCredentials, String, SyncUser.Callback)
.IllegalArgumentException
- if user name is either null
or empty.public static SyncCredentials custom(String userIdentifier, String identityProvider, Map<String,Object> userInfo)
identityProvider
and
userInfo
used.userIdentifier
- String identifying the user. Usually a username or user token.identityProvider
- provider used to verify the credentials.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()
.SyncUser.loginAsync(SyncCredentials, String, SyncUser.Callback)
.IllegalArgumentException
- if any parameter is either null
or empty.public static SyncCredentials accessToken(String accessToken, String identifier)
SyncUser.login(SyncCredentials, String)
will always
succeed, but accessing any Realm after might fail if the token is no longer valid.accessToken
- user's access token.identifier
- user identifier.SyncUser.loginAsync(SyncCredentials, String, SyncUser.Callback)
public String getIdentityProvider()
public String getUserIdentifier()
SyncCredentials.IdentityProvider
used.public Map<String,Object> getUserInfo()
SyncCredentials.IdentityProvider
used.