public class Credentials extends Object
Credentials.IdentityProvider.EMAIL_PASSWORD
provider is enabled
by default. All other providers must be enabled on MongoDB Realm to work.
Note that users wanting to login using Email/Password must register first using
EmailPasswordAuth.registerUser(String, String)
.
// Example
App app = new App("app-id");
Credentials credentials = Credentials.emailPassword("email", "password");
User user = app.loginAsync(credentials, new App.Callback<User>() {
\@Override
public void onResult(Result<User> result) {
if (result.isSuccess() {
handleLogin(result.get());
} else {
handleError(result.getError());
}
}
));
}
Modifier and Type | Class and Description |
---|---|
static class |
Credentials.IdentityProvider
This enum contains the list of identity providers supported by MongoDB Realm.
|
Modifier and Type | Method and Description |
---|---|
static Credentials |
anonymous()
Creates credentials representing an anonymous user.
|
static Credentials |
apiKey(String key)
Creates credentials representing a login using an API key.
|
static Credentials |
apple(String idToken)
Creates credentials representing a login using an Apple ID token.
|
String |
asJson()
Returns the credentials object serialized as a json string.
|
static Credentials |
customFunction(String functionName,
Object... arguments)
FIXME
|
static Credentials |
emailPassword(String email,
String password)
Creates credentials representing a login using email and password.
|
static Credentials |
facebook(String accessToken)
Creates credentials representing a login using an Facebook access token.
|
Credentials.IdentityProvider |
getIdentityProvider()
Returns the id for the provider used to authenticate with.
|
static Credentials |
google(String googleToken)
Creates credentials representing a login using an Google access token.
|
static Credentials |
jwt(String jwtToken)
Creates credentials representing a login using an JWT Token.
|
public static Credentials anonymous()
Logging the user out again means that data is lost with no means of recovery and it isn't possible to share the user details across devices.
The anonymous user must be linked to another real user to preserve data after a log out.
App.loginAsync(Credentials, App.Callback)
.public static Credentials apiKey(String key)
This provider must be enabled on MongoDB Realm to work.
key
- the API key to use for login.App.loginAsync(Credentials, App.Callback)
.public static Credentials apple(String idToken)
This provider must be enabled on MongoDB Realm to work.
idToken
- the ID token generated when using your Apple login.App.loginAsync(Credentials, App.Callback)
.public static Credentials customFunction(String functionName, Object... arguments)
This provider must be enabled on MongoDB Realm to work.
App.loginAsync(Credentials, App.Callback)
.public static Credentials emailPassword(String email, String password)
email
- email of the user logging in.password
- password of the user logging in.App.loginAsync(Credentials, App.Callback)
.public static Credentials facebook(String accessToken)
This provider must be enabled on MongoDB Realm to work.
accessToken
- the access token returned when logging in to Facebook.App.loginAsync(Credentials, App.Callback)
.public static Credentials google(String googleToken)
This provider must be enabled on MongoDB Realm to work.
googleToken
- the access token returned when logging in to Google.App.loginAsync(Credentials, App.Callback)
.public static Credentials jwt(String jwtToken)
This provider must be enabled on MongoDB Realm to work.
jwtToken
- the jwt token returned after a custom login to a another service.App.loginAsync(Credentials, App.Callback)
.public Credentials.IdentityProvider getIdentityProvider()
public String asJson()