Customer authentication
Registering a customer account
Register a new customer with email, password, and optional data. This method requires RegisterCustomer Builder Pattern object with the customer’s email, password, and optional data. Fields that were not provided are not modified. The method returns an IApiCall object needed to execute the request. Remember that an account becomes active only after successful email verification.
Do NOT allow signing in again (or signing up) when a customer is already signed in. Sign the customer out first.
Do not create multiple instances nor call this method multiple times before execution.
This method is a global operation and does not require authorization.
Method name: Client.registerAccount(registerClient)
Declaration
public static IApiCall registerAccount(@NonNull RegisterClient registerClient)
Parameters
Parameter | Type | Mandatory | Default |
---|---|---|---|
registerClient | RegisterClient | yes | - |
Return Value
IApiCall object to execute the request.
Example
private IApiCall signUpCall;
private void signUp(RegisterClient registerClient) {
if (signUpCall != null) signUpCall.cancel();
signUpCall = Client.registerAccount(registerClient);
signUpCall.onSubscribe(() -> toggleLoading(true))
.doFinally(() -> toggleLoading(false))
.execute(this::onSignUpSuccessful, this::onSignUpFailure);
}
Sign in a customer
Sign in a customer in order to obtain the JWT token, which can be used in subsequent requests.
The token is valid for 1 hour (unless configured otherwise in Synerise) and the SDK will refresh the token before each call if it is close to expiring (but not yet expired).
The method requires a valid and non-null email and password. Device ID is optional.
The method returns IApiCall
to execute the request.
Do NOT allow signing in again (or signing up) when a customer is already signed in. Sign the customer out first.
Do not create multiple instances nor call this method multiple times before execution.
This method is a global operation and does not require authorization.
Method name: Client.signIn(email, password)
Declaration
public static IApiCall signIn(@NonNull String email, @NonNull String password)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
String | yes | - | Customer’s email | |
password | String | yes | - | Customer’s password |
Return Value
IApiCall object to execute the request.
Example
private IApiCall signInCall;
private void signIn(String login, String password) {
if (signInCall != null) signInCall.cancel();
signInCall = Client.signIn(login, password);
signInCall.onSubscribe(() -> toggleLoading(true))
.execute(() -> onSignInSuccessful(login), () -> onSignInFailure());
}
Sign in conditionally
Use this method to authenticate conditionally
Method name: Client.signInConditionally(email, password)
Declaration
public static IDataApiCall<AuthConditions> signInConditionally(@NonNull String email, @NonNull String password)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
String | yes | - | Client’s email | |
password | String | yes | - | Client’s password |
Return Value
IDataApiCall<AuthConditions> object to execute the request.
Example
private IDataApiCall<AuthConditions> call;
if (call != null) call.cancel();
call = Client.signInConditionally(email, password));
call.execute(this::onSuccess, this::onFailure);
Activate a customer account
Activate a customer with email. This method requires the customer’s email. The method returns an IApiCall object needed to execute the request. This method is a global operation and does not require authorization.
Method name: Client.activateAccount(email)
Declaration
public static IApiCall activateAccount(String email)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
String | yes | - | Customer’s email |
Return Value
IApiCall object to execute the request.
Example
private IApiCall call;
if (call != null) call.cancel();
call = Client.activateAccount(email);
call.execute(this::onSuccess, this::onError);
Confirm a customer account
Confirm a customer’s account with token.
The The method returns the HTTP 400 status code if the account is already confirmed or 404 if the account does not exist. The method returns an IApiCall object needed to execute the request. This method is a global operation and does not require authorization.
Method name: Client.confirmAccount(token)
Declaration
public static IApiCall confirmAccount(String token)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
token | String | yes | - | Customer’s token |
Return Value
IApiCall object to execute the request.
Example
private IApiCall call;
if (call != null) call.cancel();
call = Client.confirmAccount(token);
call.execute(this::onSuccess, this::onError);
Authenticate with third party
Use this method to authenticate with Facebook, OAuth, or Google.
This method returns an IApiCall object needed to execute the request. This method is a global operation and does not require authorization.
Method name: Client.authenticate(token, clientIdentityProvider, agreements, attributes, authId)
Declaration
public static IApiCall authenticate(String token, ClientIdentityProvider provider, Agreements agreements, Attributes attributes, String authId)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
token | String | yes | - | Token retrieved from OAuth, Facebook, or Google authorization |
provider | ClientIdentityProvider | yes | - | Token provider |
agreements | Agreements | no | - | Optional agreements |
attributes | Attributes | no | - | Optional attributes |
authId | String | no | - | AuthenticationID to decrease the number of UUID refreshes |
authId
must be unique for every client.Return Value
IApiCall object to execute the request.
Example
private IApiCall call;
if (call != null) call.cancel();
call = Client.authenticate(token, provider, null, null, null);
call.execute(this::onSuccess, this::onFailure);
Authenticate conditionally
Use this method to authenticate conditionally
This method returns an IDataApiCall object needed to execute the request. This method is a global operation and does not require authorization.
Method name: Client.signInConditionally(email, password)
Declaration
public static IDataApiCall<AuthConditions> signInConditionally(@NonNull String email, @NonNull String password)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
String | yes | - | Client’s email | |
password | String | yes | - | Client’s password |
Return Value
IDataApiCall<AuthConditions> object to execute the request.
Example
private IDataApiCall<AuthConditions> call;
if (call != null) call.cancel();
call = Client.signInConditionally(email, password));
call.execute(this::onSuccess, this::onFailure);
Authenticate a customer by Facebook with registration
Use this method to sign in with Facebook. HTTP 401 status code is returned if the provided Facebook token and/or API Key is invalid.
This method returns an IApiCall object needed to execute the request. This method is a global operation and does not require authorization.
Method name: Client.authenticateByFacebook(facebookToken, agreements, attributes, authId)
Declaration
public static IApiCall authenticateByFacebook(@NonNull String facebookToken, @Nullable Agreements agreements, @Nullable Attributes attributes, @Nullable String authId)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
facebookToken | String | yes | - | Token retrieved from Facebook SDK |
agreements | Agreements | no | — | Marketing agreements |
attributes | Attributes | no | — | Additional attributes |
authId | String | no | — | Optional authId to decrease the number of UUID refreshes |
Return Value
IApiCall object to execute the request.
Example
private IApiCall signInFacebookCall;
private void signInFacebook(String facebookToken) {
if (signInFacebookCall != null) signInFacebookCall.cancel();
signInFacebookCall = Client.authenticateByFacebook(facebookToken, null, null, null);
signInFacebookCall.onSubscribe(() -> toggleFacebookLoading(true))
.execute(this::onSignInFacebookSuccess, this::onSignInFacebookError);
}
Authenticate a customer by Facebook without registration
This method is deprecated. Use Client.authenticate instead.
Use this method to sign in with an already registered Facebook account.
HTTP 401 status code is returned if no account is associated with the provided facebook token. This method returns an IApiCall object needed to execute the request. This method is a global operation and does not require authorization.
Method name: Client.authenticateByFacebookRegistered(facebookToken, authId)
Declaration
public static IApiCall authenticateByFacebookRegistered(@NonNull String facebookToken, @Nullable String authId)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
facebookToken | String | yes | - | Token retrieved from Facebook SDK |
authId | String | no | — | Optional authId to decrease the number of UUID refreshes |
Return Value
IApiCall object to execute the request.
Example
private IApiCall signInFacebookRegisteredCall;
private void signInFacebookRegistered(String facebookToken) {
if (signInFacebookRegisteredCall != null) signInFacebookRegisteredCall.cancel();
signInFacebookRegisteredCall = Client.authenticateByFacebookRegistered(facebookToken, null);
signInFacebookRegisteredCall.onSubscribe(() -> toggleFacebookLoading(true))
.execute(this::onSignInFacebookSuccess, this::onSignInFacebookError);
}
Authenticate a customer by OAuth
Use this method to sign in with an already prepared OAuth authorization token.
the HTTP 401 status code is returned if the provided access token and/or API Key is invalid. This method returns an IApiCall object needed to execute the request. This method is a global operation and does not require authorization.
Method name: Client.authenticateByOAuth(accessToken, agreements, attributes, authId)
Declaration
public static IApiCall authenticateByOAuth(@NonNull String accessToken, @Nullable Agreements agreements, @Nullable Attributes attributes, @Nullable String authId)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
accessToken | String | yes | - | Token retrieved from OAuth authorization |
agreements | Agreements | no | — | Optional agreements |
attributes | Attributes | no | — | Optional attributes |
authId | String | no | — | AuthenticationId to decrease the number of UUID refreshes |
authId
should be unique for every user.Return Value
IApiCall object to execute the request.
Example
private IApiCall call;
if (call != null) call.cancel();
call = Client.authenticateByOAuth(token, null, null, null);
call.execute(this::onSuccess, this::onFailure);
Authenticate a customer by OAuth without registration
This method is deprecated. Use Client.authenticate instead.
Use this method to sign in with already registered account.
This method returns an IApiCall object needed to execute the request. This method is a global operation and does not require authorization.
Method name: Client.authenticateByOAuth(accessToken, agreements, attributes, authId)
Declaration
public static IApiCall authenticateByOAuthIfRegistered(@NonNull String accessToken, @Nullable String authId)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
accessToken | String | yes | - | Token retrieved from OAuth authorization |
authId | String | no | — | AuthenticationId to decrease the number of UUID refreshes |
Return Value
IApiCall object to execute the request.
Example
private IApiCall call;
if (call != null) call.cancel();
call = Client.authenticateByOAuth(token, null);
call.execute(this::onSuccess, this::onFailure);
Check if a customer is signed in
Check if a customer is signed in (whether the customer’s token is authorized).
Method name: Client.isSignedIn()
Declaration
public static boolean isSignedIn()
Parameters
No parameters.
Return Value
Boolean defining whether a customer is signed in or not.
Example
boolean isSignedIn = Client.isSignedIn()
Sign out a customer
Signing a customer out clears the customer’s JWT token.
Method name: Client.signOut()
Declaration
public static void signOut()
Parameters
No parameters.
Return Value
Nothing is returned.
Example
Client.signOut();
Sign out a customer with backend call
Signing a customer out clears the customer’s JWT token and optionally removes the UUID.
Method name: Client.signOut(mode)
Declaration
public static void signOut(ClientSignOutMode mode)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
mode | ClientSignOutMode | yes | - | Client sign out mode |
Return Value
Nothing is returned.
Example
Client.signOut(mode);
Set client state change callback
Set your own ClientStateChangeListener to get optional callbacks.
Method name: Client.setOnClientStateChangeListener(listener);
Declaration
public static void setOnClientStateChangeListener(OnClientStateChangeListener listener)
Parameters
Parameter | Type | Mandatory | Default | Description |
---|---|---|---|---|
listener | OnClientStateChangeListener | yes | - | interface to handle client state change |
Return Value
No value is returned.
Example
Client.setOnClientStateChangeListener(listener);
Remove client state change callback
Remove your own ClientStateChangeListener.
Method name: Client.removeClientStateChangeListener();
Declaration
public static void removeClientStateChangeListener()
Parameters
No parameters required.
Return Value
No value is returned.
Example
Client.removeClientStateChangeListener();