public class Credentials extends Object
Credentials.Provider.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.Provider
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 a user 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(Document arguments)
Creates credentials representing a remote function from MongoDB Realm using a
Document which will be parsed as an argument to the remote function, so the keys must
match the format and names the function expects. |
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 a Facebook access token.
|
Credentials.Provider |
getIdentityProvider()
Returns the identity provider used to authenticate with.
|
static Credentials |
google(String authorizationCode)
Creates credentials representing a login using a Google Authorization Code.
|
static Credentials |
jwt(String jwtToken)
Creates credentials representing a login using a 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(Document arguments)
Document
which will be parsed as an argument to the remote function, so the keys must
match the format and names the function expects.
This provider must be enabled on MongoDB Realm to work.
arguments
- document containing the function arguments.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 authorizationCode)
This provider must be enabled on MongoDB Realm to work.
authorizationCode
- the authorization code 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.Provider getIdentityProvider()
public String asJson()