This provides a reference for the main static methods defined on ApproovService. These are available if you import:
Java
import io.approov.service.httpsurlconn.ApproovService;Various methods may throw an ApproovException if there is a problem. The method getMessage() provides a descriptive message.
If a method throws an ApproovNetworkException, a user-initiated retry should be allowed.
If a method throws an ApproovRejectionException, the app failed attestation. Additional methods getARC() and getRejectionReasons() provide more detail when available.
Initializes the Approov SDK and enables the Approov features.
void initialize(Context context, String config)The application context must be provided using the context parameter. It is possible to pass an empty config string to indicate that no initialization is required. Only do this if you are also using a different Approov service layer in your app and that layer initializes the shared SDK first.
Sets the ApproovServiceMutator instance used to customize request preparation and attestation handling.
void setServiceMutator(ApproovServiceMutator mutator)Passing null restores the default behavior.
Gets the currently active mutator.
ApproovServiceMutator getServiceMutator()Deprecated compatibility alias for setServiceMutator.
void setApproovInterceptorExtensions(ApproovServiceMutator mutator)Deprecated compatibility alias for getServiceMutator.
ApproovServiceMutator getApproovInterceptorExtensions()If proceed is true then request preparation may continue when it is not possible to obtain an Approov token due to a networking failure.
void setProceedOnNetworkFail(boolean proceed)Deprecated: use setServiceMutator instead to control this behavior.
Gets the legacy proceed-on-network-failure flag.
boolean getProceedOnNetworkFail()Deprecated: use setServiceMutator instead to control this behavior.
If shouldUse is true then the Approov fetch status, for example NO_NETWORK, is used as the token header value if the actual token fetch fails or returns an empty token.
void setUseApproovStatusIfNoToken(boolean shouldUse)Gets the current status-as-token behavior flag.
boolean getUseApproovStatusIfNoToken()Sets a development key in order to force the app to pass attestation in a test environment.
void setDevKey(String devKey) throws ApproovExceptionSets the header that carries the Approov token and an optional prefix string such as Bearer .
void setApproovHeader(String header, String prefix)Gets the header currently used for the Approov token.
String getApproovTokenHeader()Gets the prefix currently used before the Approov token value.
String getApproovTokenPrefix()Sets the header used to transmit any optional Approov TraceID debug value.
void setApproovTraceIDHeader(String header)Passing null disables the TraceID header.
Gets the header currently used for the optional Approov TraceID.
String getApproovTraceIDHeader()Sets a binding header used for token binding.
void setBindingHeader(String header)Adds a header that should be subject to secure string substitution.
void addSubstitutionHeader(String header, String requiredPrefix)Removes a header previously added using addSubstitutionHeader.
void removeSubstitutionHeader(String header)Gets the currently configured substitution headers.
Map<String, String> getSubstitutionHeaders()Adds a query parameter key that should be subject to secure string substitution.
void addSubstitutionQueryParam(String key)Removes a query parameter key previously added using addSubstitutionQueryParam.
void removeSubstitutionQueryParam(String key)Gets the currently configured substitution query parameters.
Map<String, Pattern> getSubstitutionQueryParams()Adds an exclusion URL regular expression. Matching URLs are not subject to Approov protection.
void addExclusionURLRegex(String urlRegex)Removes an exclusion URL regular expression previously added using addExclusionURLRegex.
void removeExclusionURLRegex(String urlRegex)Starts a background Approov fetch operation early so a later token or secure string fetch may use cached data.
void prefetch()Performs a precheck to determine if the app will pass attestation.
void precheck() throws ApproovExceptionThis may require network access and should not be called from the UI thread.
Gets the device ID used by Approov to identify the current app installation.
String getDeviceID() throws ApproovExceptionDirectly sets the data hash to be included in subsequently fetched Approov tokens.
void setDataHashInToken(String data) throws ApproovExceptionThis is an alternative to using setBindingHeader; you should not use both at the same time.
Performs an Approov token fetch for the given URL.
String fetchToken(String url) throws ApproovExceptionUse this when it is not possible to use addApproov(...) or addApproovToConnection(...) to prepare the request automatically.
Deprecated alias for getAccountMessageSignature.
String getMessageSignature(String message) throws ApproovExceptionGets the account message signature for the given message.
String getAccountMessageSignature(String message) throws ApproovExceptionGets the install message signature for the given message.
String getInstallMessageSignature(String message) throws ApproovExceptionFetches a secure string with the given key. If newDef is not null then the string definition is updated for the current app installation.
String fetchSecureString(String key, String newDef) throws ApproovExceptionFetches a custom JWT with the given marshaled JSON payload.
String fetchCustomJWT(String payload) throws ApproovExceptionObtains the last Attestation Response Code, provided a network request to the Approov servers has succeeded.
String getLastARC()This returns an empty string if no suitable ARC is available.
Sets an install attributes token to be sent to the server and associated with this app installation for future token fetches.
void setInstallAttrsInToken(String attrs) throws ApproovExceptionPrepares an HttpsURLConnection request in place by adding the Approov token header, applying header substitutions, applying pinning, and invoking the configured mutator when a wrapper is not required.
void addApproov(HttpsURLConnection request) throws ApproovExceptionThis preserves the original binary-compatible API. Use addApproovToConnection(...) for query parameter substitution or deferred body-aware processing.
Prepares an HttpsURLConnection request and returns the connection reference that should be used for the network call.
HttpsURLConnection addApproovToConnection(HttpsURLConnection request) throws ApproovExceptionIn the common case this is the same instance that was passed in. If configured query substitutions change the effective URL, or if deferred body-aware processing is required, then a wrapped connection is returned instead.
Applies all configured query parameter substitutions to the supplied URL.
URL substituteQueryParams(URL url) throws ApproovExceptionSince this modifies the URL itself, it must be done before opening the HttpsURLConnection.
Substitutes a single query parameter in the supplied URL.
URL substituteQueryParam(URL url, String queryParameter) throws ApproovExceptionSince this modifies the URL itself, it must be done before opening the HttpsURLConnection.