Package com.clover.sdk.util
Class CloverAuth
- java.lang.Object
-
- com.clover.sdk.util.CloverAuth
-
public class CloverAuth extends Object
Obtain authentication information. The primary use of this class is to get the Clover cloud base URL (seeCloverAuth.AuthResult.baseUrl
) and access token (seeCloverAuth.AuthResult.authToken
) used for REST API calls to the Clover cloud. The information returned fromauthenticate(Context, boolean, Long, TimeUnit)
is cached for 24 hours on the device. After 24 hours the information is validated with the Clover cloud. This means that periodically, a call toauthenticate(Context, boolean, Long, TimeUnit)
will result in a blocking network request. Your app should be prepared for this. Do not call this method on the main UI thread, and be prepared to communicate any delays to the user. Access tokens are guaranteed to be valid for at least 24 hours. There is no situation where you can obtain an invalid access token from this method, as long as your app is a valid Clover app in the Clover cloud and is installed to this merchant. The information returned fromauthenticate(Context, boolean, Long, TimeUnit)
should not be persisted or cached. Call this method prior to all request to the Clover cloud. The forceValidate argument toauthenticate(Context, boolean, Long, TimeUnit)
causes the token to be validated always, as opposed to every 24 hours as noted above. Use of this is atypical. The app invoking methods in this class must be published Clover developer app and be installed to this merchant in the Clover cloud to succeed. It is not sufficient to only sideload an app. See this Clover documentation for more information about making REST API calls from a Clover app.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CloverAuth.AuthResult
Container for the data returned when an account authenticates with the Clover service.
-
Field Summary
Fields Modifier and Type Field Description static String
AUTH_AUTHORITY
static Uri
AUTH_URI
static String
METHOD_AUTH
static String
METHOD_AUTH_PERMISSIONS
-
Constructor Summary
Constructors Constructor Description CloverAuth()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static CloverAuth.AuthResult
authenticate(Activity activity, Account account)
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)static CloverAuth.AuthResult
authenticate(Activity activity, Account account, boolean forceValidateToken)
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)static CloverAuth.AuthResult
authenticate(Activity activity, Account account, boolean forceValidateToken, Long timeout, TimeUnit unit)
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)static CloverAuth.AuthResult
authenticate(Context context)
Equivalent to callingauthenticate(Context, boolean, Long, TimeUnit)
with force validate false, and a timeout of 20 seconds.static CloverAuth.AuthResult
authenticate(Context context, boolean forceValidateToken, Long timeout, TimeUnit unit)
Authenticates with the Clover service.static CloverAuth.AuthResult
authenticate(Context context, Account account)
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)static CloverAuth.AuthResult
authenticate(Context context, Account account, boolean forceValidateToken)
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)static CloverAuth.AuthResult
authenticate(Context context, Account account, boolean forceValidateToken, Long timeout, TimeUnit unit)
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)
-
-
-
Field Detail
-
AUTH_AUTHORITY
public static final String AUTH_AUTHORITY
- See Also:
- Constant Field Values
-
AUTH_URI
public static final Uri AUTH_URI
-
METHOD_AUTH
public static final String METHOD_AUTH
- See Also:
- Constant Field Values
-
METHOD_AUTH_PERMISSIONS
public static final String METHOD_AUTH_PERMISSIONS
- See Also:
- Constant Field Values
-
-
Method Detail
-
authenticate
@Deprecated public static CloverAuth.AuthResult authenticate(Activity activity, Account account, boolean forceValidateToken) throws OperationCanceledException, AuthenticatorException, IOException
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)Authenticates with the Clover service. This method makes a network call to the Clover service. It should be run on a background thread. This method will block indefinitely for a result.
-
authenticate
@Deprecated public static CloverAuth.AuthResult authenticate(Activity activity, Account account, boolean forceValidateToken, Long timeout, TimeUnit unit) throws OperationCanceledException, AuthenticatorException, IOException
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)Authenticates with the Clover service. This method makes a network call to the Clover service. It should be run on a background thread.- Parameters:
activity
- the activity that initiated the authenticationaccount
- the account used for authenticationforceValidateToken
- flag for if token should be validated against API. Increases response latency, use only when necessary.timeout
- the maximum time to waitunit
- the time unit of the timeout argument. This must not be null.- Throws:
OperationCanceledException
AuthenticatorException
IOException
- See Also:
authenticate(Context, boolean, Long, TimeUnit)
-
authenticate
@Deprecated public static CloverAuth.AuthResult authenticate(Context context, Account account, boolean forceValidateToken) throws OperationCanceledException, AuthenticatorException, IOException
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)
-
authenticate
@Deprecated public static CloverAuth.AuthResult authenticate(Context context, Account account, boolean forceValidateToken, Long timeout, TimeUnit unit) throws OperationCanceledException, AuthenticatorException, IOException
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)
-
authenticate
@Deprecated public static CloverAuth.AuthResult authenticate(Activity activity, Account account) throws OperationCanceledException, AuthenticatorException, IOException
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)
-
authenticate
@Deprecated public static CloverAuth.AuthResult authenticate(Context context, Account account) throws OperationCanceledException, AuthenticatorException, IOException
Deprecated.Useauthenticate(Context, boolean, Long, TimeUnit)
(required when targeting SDK level 26 or higher)
-
authenticate
public static CloverAuth.AuthResult authenticate(Context context) throws InterruptedException, ExecutionException, TimeoutException
Equivalent to callingauthenticate(Context, boolean, Long, TimeUnit)
with force validate false, and a timeout of 20 seconds.
-
authenticate
public static CloverAuth.AuthResult authenticate(Context context, boolean forceValidateToken, Long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Authenticates with the Clover service. This method may result in a network call to the Clover cloud. It should be run on a background thread. It is recommended that you preferauthenticate(Context)
over this method as it provides reasonable defaults for arguments. This method differs fromauthenticate(Context, Account, boolean, Long, TimeUnit)
in that it does not require anAccount
argument. If your app targets API 26 or higher you MUST use this method over the variants that accept an account as your app will be restricted from obtaining the Clover account fromCloverAccount
(viaAccountManager
).- Parameters:
context
- the context that initiated the authentication.forceValidateToken
- should the token should be validated against the Clover cloud? Tokens are validated every 24 hours regardless of this flag. Passing true here is atypical and is discouraged.timeout
- the maximum time to wait. If null, wait forever. Typically this call will finish in the order of tens of milliseconds, however, every 24 hours the access token is validated against the Clover cloud, causing this call to result in a blocking network request that can take longer.unit
- the time unit of the timeout argument. If null, wait forever.- Throws:
InterruptedException
ExecutionException
TimeoutException
-
-