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.

Note:

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.

Note:

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

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
email 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 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 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


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

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);

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();
😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.