Class DittoAuthenticator
java.lang.Object
com.ditto.java.DittoAuthenticator
Handles authentication with Ditto Cloud for remote synchronization.
Use this class to log in to a remote authentication service when using an
OnlineWithAuthentication or Online identity.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandler for authentication expiration events.static interfaceCallback invoked when a login operation completes.static interfaceCallback invoked when a login operation completes with client info.static final recordResult of a login operation.static interfaceFunction to perform cleanup operations during logout.static interfaceListener for authentication status changes. -
Method Summary
Modifier and TypeMethodDescription@NonNull DittoAuthenticationStatusReturns the current authentication status.login(@NonNull String token, @NonNull DittoAuthenticationProvider provider) Logs in to Ditto with a third-party authentication token.Logs in to Ditto with a third-party authentication token.login(@NonNull String token, @NonNull String provider, @NonNull DittoAuthenticator.LoginCallbackWithClientInfoJSON callback) Logs in to Ditto with a third-party authentication token using a callback.@NonNull CompletionStage<@Nullable DittoException> loginWithCredentials(@NonNull String username, @NonNull String password, @NonNull String provider) Logs in to Ditto with a username and password.loginWithCredentials(@NonNull String username, @NonNull String password, @NonNull String provider, @NonNull DittoAuthenticator.LoginCallback callback) Logs in to Ditto with a username and password using a callback.voidlogout()Logs out of Ditto.voidlogout(@Nullable DittoAuthenticator.LogoutCleanup cleanup) Logs out of Ditto with optional cleanup.Returns a Flow Publisher that emits authentication status changes.observeStatus(@NonNull DittoAuthenticator.StatusListener listener) Observes authentication status changes using a listener.voidsetCallback(@NonNull DittoAuthenticationCallback callback) Sets the authentication callback to receive authentication events.voidsetExpirationHandler(@NonNull DittoAuthenticator.ExpirationHandler expirationHandler) Sets a handler to be called when authentication is about to expire.
-
Method Details
-
setCallback
Sets the authentication callback to receive authentication events.- Parameters:
callback- theDittoAuthenticationCallbackto be notified of authentication events.
-
setExpirationHandler
Sets a handler to be called when authentication is about to expire.- Parameters:
expirationHandler- theDittoAuthenticator.ExpirationHandlerto handle expiring authentication.
-
getStatus
Returns the current authentication status.- Returns:
- the current
DittoAuthenticationStatus.
-
login
public @NonNull CompletionStage<DittoAuthenticator.LoginResult> login(@NonNull String token, @NonNull DittoAuthenticationProvider provider) Logs in to Ditto with a third-party authentication token. The returnedCompletionStagewill complete once the login attempt finishes. TheDittoAuthenticator.LoginResultcontains optional client info JSON from the auth webhook and an error if the login failed.- Parameters:
token- the authentication token required to log in.provider- theDittoAuthenticationProvider(development or custom).- Returns:
- a
CompletionStagethat completes with theDittoAuthenticator.LoginResult.
-
login
public @NonNull CompletionStage<DittoAuthenticator.LoginResult> login(@NonNull String token, @NonNull String provider) Logs in to Ditto with a third-party authentication token. The returnedCompletionStagewill complete once the login attempt finishes. TheDittoAuthenticator.LoginResultcontains optional client info JSON from the auth webhook and an error if the login failed.- Parameters:
token- the authentication token required to log in.provider- the name of the authentication provider.- Returns:
- a
CompletionStagethat completes with theDittoAuthenticator.LoginResult.
-
loginWithCredentials
public @NonNull CompletionStage<@Nullable DittoException> loginWithCredentials(@NonNull String username, @NonNull String password, @NonNull String provider) Logs in to Ditto with a username and password.- Parameters:
username- the username component of the credentials.password- the password component of the credentials.provider- the name of the authentication provider.- Returns:
- a
CompletionStagethat completes with aDittoExceptionif login fails, or null on success.
-
login
public DittoAsyncCancellable login(@NonNull String token, @NonNull String provider, @NonNull DittoAuthenticator.LoginCallbackWithClientInfoJSON callback) Logs in to Ditto with a third-party authentication token using a callback.- Parameters:
token- the authentication token required to log in.provider- the name of the authentication provider.callback- theDittoAuthenticator.LoginCallbackWithClientInfoJSONto be called when login completes.- Returns:
- a
DittoAsyncCancellablethat can be used to cancel the login attempt.
-
loginWithCredentials
public DittoAsyncCancellable loginWithCredentials(@NonNull String username, @NonNull String password, @NonNull String provider, @NonNull DittoAuthenticator.LoginCallback callback) Logs in to Ditto with a username and password using a callback.- Parameters:
username- the username component of the credentials.password- the password component of the credentials.provider- the name of the authentication provider.callback- theDittoAuthenticator.LoginCallbackto be called when login completes.- Returns:
- a
DittoAsyncCancellablethat can be used to cancel the login attempt.
-
logout
public void logout()Logs out of Ditto. This will stop sync, shut down all replication sessions, and remove any cached authentication credentials. Note that this does not remove any data from the store. -
logout
Logs out of Ditto with optional cleanup. This will stop sync, shut down all replication sessions, and remove any cached authentication credentials. The optional cleanup function allows you to perform any required cleanup of the store as part of the logout process.- Parameters:
cleanup- an optionalDittoAuthenticator.LogoutCleanupfunction to perform cleanup operations.
-
observeStatus
Returns a Flow Publisher that emits authentication status changes.- Returns:
- a
Flow.Publisherthat emitsDittoAuthenticationStatusupdates.
-
observeStatus
Observes authentication status changes using a listener.- Parameters:
listener- theDittoAuthenticator.StatusListenerto be notified of status changes.- Returns:
- an
AutoCloseablethat can be used to stop observing.
-