Ditto 4.13.1
Loading...
Searching...
No Matches
DittoSDK.DittoAuthenticator Class Reference

Provides access to authentication information and methods for logging on to Ditto Cloud. Relevant when using an OnlineWithAuthentication or an Online identity. More...

Public Member Functions

async Task< DittoErrorLoginWithToken (string token, string provider)
 Log in to Ditto with a third-party token.
async Task<(string clientInfoJson, DittoError error)> Login (string token, string provider)
 Log in to Ditto with a third-party token.
Task< string > LoginAsync (string token, string provider)
 Logs in to Ditto using a third-party authentication token.
Task< string > LoginAsync (string token, DittoAuthenticationProvider provider)
 Logs in to Ditto using a third-party authentication token.
async Task< DittoErrorLoginWithCredentials (string username, string password, string provider)
 Log in to Ditto with a username and password.
Task LoginWithCredentialsAsync (string username, string password, string provider)
 Logs in to Ditto using a username and password with the specified authentication provider.
Task LoginWithCredentialsAsync (string username, string password, DittoAuthenticationProvider provider)
 Logs in to Ditto using a username and password with the specified authentication provider.
IDisposable ObserveStatus (Action< DittoAuthenticationStatus > callback)
 Registers a callback that is called whenever the authentication status changes.
void Logout (Action< Ditto > cleanupAction=null)
 Log out of Ditto.

Properties

IDittoAuthenticationDelegate AuthenticationDelegate [get, set]
 Gets the authentication delegate for this Ditto instance, as provided through DittoIdentity.OnlineWithAuthentication(...).
DittoAuthenticationExpirationHandler ExpirationHandler [get, set]
 Gets or sets the handler that will be invoked when authentication for this Ditto instance is about to expire.
DittoAuthenticationStatus Status [get]
 Gets the current authentication status.

Detailed Description

Provides access to authentication information and methods for logging on to Ditto Cloud. Relevant when using an OnlineWithAuthentication or an Online identity.

Member Function Documentation

◆ Login()

async Task<(string clientInfoJson, DittoError error)> DittoSDK.DittoAuthenticator.Login ( string token,
string provider )
inline

Log in to Ditto with a third-party token.

If authentication has failed then the returned DittoError will be non-null. The returned clientInfoJson string will not be null if the auth webhook endpoint returned any JSON value under the clientInfo key. That JSON value is what will be passed via the clientInfoJson string, if it's provided.

Parameters
tokenThe authentication token required to log in.
providerThe name of the authentication provider.
Returns
A tuple containing the clientInfoJson and the DittoError. The error will be null if the authentication succeeded.

◆ LoginAsync() [1/2]

Task< string > DittoSDK.DittoAuthenticator.LoginAsync ( string token,
DittoAuthenticationProvider provider )
inline

Logs in to Ditto using a third-party authentication token.

If authentication succeeds, this method returns the clientInfoJson string. If authentication fails, it throws a DittoAuthenticationException. The exception will contain any JSON returned from the authentication webhook under the clientInfo key, if available, via its ClientInfoJson property.

Parameters
tokenThe authentication token required to log in.
providerThe name of the authentication provider.
Returns
clientInfoJson string.
Exceptions
DittoAuthenticationExceptionThrown when authentication fails.

◆ LoginAsync() [2/2]

Task< string > DittoSDK.DittoAuthenticator.LoginAsync ( string token,
string provider )
inline

Logs in to Ditto using a third-party authentication token.

If authentication succeeds, this method returns the clientInfoJson string. If authentication fails, it throws a DittoAuthenticationException. The exception will contain any JSON returned from the authentication webhook under the clientInfo key, if available, via its ClientInfoJson property.

Parameters
tokenThe authentication token required to log in.
providerThe name of the authentication provider.
Returns
clientInfoJson string.
Exceptions
DittoAuthenticationExceptionThrown when authentication fails.

◆ LoginWithCredentials()

async Task< DittoError > DittoSDK.DittoAuthenticator.LoginWithCredentials ( string username,
string password,
string provider )
inline

Log in to Ditto with a username and password.

Parameters
usernameThe username component of the credentials used for log in.
passwordThe password component of the credentials used for log in.
providerThe name of the authentication provider.
Returns
A DittoError if the login attempt failed, otherwise null.

◆ LoginWithCredentialsAsync() [1/2]

Task DittoSDK.DittoAuthenticator.LoginWithCredentialsAsync ( string username,
string password,
DittoAuthenticationProvider provider )
inline

Logs in to Ditto using a username and password with the specified authentication provider.

Parameters
usernameThe username component of the credentials used for login.
passwordThe password component of the credentials used for login.
providerThe authentication provider to use. You can use built-in values like DittoAuthenticationProvider.Development or define custom ones.
Returns
A Task that completes when the login attempt finishes.
Exceptions
DittoAuthenticationExceptionThrown when authentication fails.

◆ LoginWithCredentialsAsync() [2/2]

Task DittoSDK.DittoAuthenticator.LoginWithCredentialsAsync ( string username,
string password,
string provider )
inline

Logs in to Ditto using a username and password with the specified authentication provider.

Parameters
usernameThe username component of the credentials used for login.
passwordThe password component of the credentials used for login.
providerThe authentication provider to use. You can use built-in values like DittoAuthenticationProvider.Development or define custom ones.
Returns
A Task that completes when the login attempt finishes.
Exceptions
DittoAuthenticationExceptionThrown when authentication fails.

◆ LoginWithToken()

async Task< DittoError > DittoSDK.DittoAuthenticator.LoginWithToken ( string token,
string provider )
inline

Log in to Ditto with a third-party token.

Parameters
tokenThe authentication token required to log in.
providerThe name of the authentication provider.
Returns
A DittoError if the login attempt failed, otherwise null.

◆ Logout()

void DittoSDK.DittoAuthenticator.Logout ( Action< Ditto > cleanupAction = null)
inline

Log 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. If you wish to delete data from the store then use the optional cleanupAction argument to perform any required cleanup.

Parameters
cleanupActionAn optional action that will be called with the relevant Ditto instance as the sole argument that allows you to perform any required cleanup of the store as part of the logout process.

◆ ObserveStatus()

IDisposable DittoSDK.DittoAuthenticator.ObserveStatus ( Action< DittoAuthenticationStatus > callback)
inline

Registers a callback that is called whenever the authentication status changes.

Parameters
callbackAn action reference to the caller's callback.
Returns
An IDisposable that you can use to stop this observation.

Property Documentation

◆ AuthenticationDelegate

IDittoAuthenticationDelegate DittoSDK.DittoAuthenticator.AuthenticationDelegate
getset

Gets the authentication delegate for this Ditto instance, as provided through DittoIdentity.OnlineWithAuthentication(...).

Phased out in 4.xDittoIdentity and with it IDittoAuthenticationDelegate is being phased out, please use DittoConfig-based APIs instead and set the ExpirationHandler. This API will be replaced by ExpirationHandler in v5.

◆ ExpirationHandler

DittoAuthenticationExpirationHandler DittoSDK.DittoAuthenticator.ExpirationHandler
getset

Gets or sets the handler that will be invoked when authentication for this Ditto instance is about to expire.

Important: This API is in preview and provides a closure-based replacement for the AuthenticationDelegate property, offering a more modern approach to handling authentication expiration events. This will replace the delegate pattern in v5.

Assign this property to be notified shortly before authentication expires, allowing you to log in or perform other necessary actions.

Important: If the Ditto instance was initialized with DittoConfigConnect.Server(Uri), this property must be set, and the assigned handler must perform proper authentication when triggered.

If not set, calling DittoSync.Start() will throw an ExpirationHandlerMissingException