Docs Menu
Docs Home
/ /
Atlas Device SDKs
/ / /

Class Credentials

On this page

  • io.realm.mongodb
  • Nested Class Summary
  • Method Summary
  • Inherited Methods
  • Method Detail
  • anonymous
  • apiKey
  • apple
  • asJson
  • customFunction
  • emailPassword
  • facebook
  • getIdentityProvider
  • google
  • jwt
java.lang.Object
io.realm.mongodb.Credentials

Credentials represent a login with a given login provider, and are used by the MongoDB Realm to verify the user and grant access. The 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) .

Credentials are used the following way:

// 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());
}
}
));
}

Tip

See also:

  • Authentication Providers

Modifier and Type
Class and Description
public static final
Modifier and Type
Method and Description
public static Credentials

Creates credentials representing an anonymous user.

public static Credentials

Creates credentials representing a login using a user API key.

public static Credentials
String idToken
)

Creates credentials representing a login using an Apple ID token.

public String

Returns the credentials object serialized as a json string.

public static Credentials
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.

public static Credentials
String email,
String password
)

Creates credentials representing a login using email and password.

public static Credentials
String accessToken
)

Creates credentials representing a login using a Facebook access token.

Returns the identity provider used to authenticate with.

public static Credentials
String authorizationCode
)

Creates credentials representing a login using a GoogleAuthType.AUTH_CODE Google access token.

public static Credentials

Creates credentials representing a login using a Google access token of a given GoogleAuthType .

public static Credentials
jwt (
String jwtToken
)

Creates credentials representing a login using a JWT Token.

  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

public static Credentials anonymous ()

Creates credentials representing an anonymous user.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.

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

public static Credentials apiKey (
String key
)

Creates credentials representing a login using a user API key.This provider must be enabled on MongoDB Realm to work.

Parameters

  • key - the API key to use for login.

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

public static Credentials apple (
String idToken
)

Creates credentials representing a login using an Apple ID token.This provider must be enabled on MongoDB Realm to work.

Parameters

  • idToken - the ID token generated when using your Apple login.

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

public String asJson ()

Returns the credentials object serialized as a json string.

Returns

a json serialized string of the credentials object.

public 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.

This provider must be enabled on MongoDB Realm to work.

Parameters

  • arguments - document containing the function arguments.

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

public static Credentials emailPassword (
String email,
String password
)

Creates credentials representing a login using email and password.

Parameters

  • email - email of the user logging in.

  • password - password of the user logging in.

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

public static Credentials facebook (
String accessToken
)

Creates credentials representing a login using a Facebook access token.This provider must be enabled on MongoDB Realm to work.

Parameters

  • accessToken - the access token returned when logging in to Facebook.

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

Returns the identity provider used to authenticate with.

Returns

the provider identifying the chosen credentials.

public static Credentials google (
String authorizationCode
)

Creates credentials representing a login using a GoogleAuthType.AUTH_CODE Google access token.

This provider must be enabled on MongoDB Realm to work.

Parameters

  • authorizationCode - the authorization code returned when logging in to Google.

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

public static Credentials google (
)

Creates credentials representing a login using a Google access token of a given GoogleAuthType .

This provider must be enabled on MongoDB Realm to work.

Parameters

  • token - the access token returned when logging in to Google.

  • type - the access token type

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

public static Credentials jwt (
String jwtToken
)

Creates credentials representing a login using a JWT Token. This token is normally generated after a custom OAuth2 login flow.This provider must be enabled on MongoDB Realm to work.

Parameters

  • jwtToken - the jwt token returned after a custom login to a another service.

Returns

a set of credentials that can be used to log into MongoDB Realm using App.loginAsync(Credentials, App.Callback) .

Back

AuthenticationListener