# google::play::integrity::IntegrityClient


`#include <integrity/client.h>`

Entrypoint for the Google Play Integrity API.

## Summary

The Play Integrity API helps you check that interactions and server requests are coming from a genuine PC device. By detecting potentially risky and fraudulent interactions, your app's backend server can respond with appropriate actions to prevent attacks and reduce abuse.

| ### Constructors and Destructors ||
|---|---|
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a8125f2d0977778724f9f3226848d599b()` ||
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a0bd229cc2a2e79d5a7750f52fa0c0074()` ||

| ### Public functions ||
|---|---|
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a16b2300dfd23a2cbf3096e893f70a273(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/prepare-integrity-token-params#structgoogle_1_1play_1_1integrity_1_1_prepare_integrity_token_params & params, PrepareIntegrityTokenContinuation continuation)` | `void` Warms up the Play Integrity API for requesting integrity tokens. |
| `https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a4357e1b01ef9be5eb0e6a69bb45ed021(const https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/request-integrity-token-params#structgoogle_1_1play_1_1integrity_1_1_request_integrity_token_params & params, RequestIntegrityTokenContinuation continuation)` | `void` Requests an integrity token using a [RequestTokenData](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/request-token-data#structgoogle_1_1play_1_1integrity_1_1_request_token_data) obtained from a successful [PrepareIntegrityToken](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a16b2300dfd23a2cbf3096e893f70a273) call. |

## Public functions

### IntegrityClient

```
 IntegrityClient()
```

### PrepareIntegrityToken

```
void PrepareIntegrityToken(
  const PrepareIntegrityTokenParams & params,
  PrepareIntegrityTokenContinuation continuation
)
```
Warms up the Play Integrity API for requesting integrity tokens.

Before requesting an integrity token (see [RequestIntegrityToken](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a4357e1b01ef9be5eb0e6a69bb45ed021)), you must prepare (or "warm up") the Play Integrity API. This allows Google Play to intelligently cache partial attestation information on the device in order to decrease the latency on the critical path when you make a request for an integrity verdict.

On success, the continuation will be called with a [PrepareIntegrityTokenResultValue](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/prepare-integrity-token-result-value#structgoogle_1_1play_1_1integrity_1_1_prepare_integrity_token_result_value) containing a [RequestTokenData](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/request-token-data#structgoogle_1_1play_1_1integrity_1_1_request_token_data) that should be used to request an integrity token. This data should be cached in-memory and reused for the duration of the application's session for calls to [RequestIntegrityToken](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a4357e1b01ef9be5eb0e6a69bb45ed021).

Only if your application determines that it is necessary to entirely revaluate the integrity verdict should a call to [PrepareIntegrityToken](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a16b2300dfd23a2cbf3096e893f70a273) be made.

<br />

Details Parameters `params` Parameters containing a Google Cloud project number. `continuation` The async callback to return the integrity token provider to.

### RequestIntegrityToken

```
void RequestIntegrityToken(
  const RequestIntegrityTokenParams & params,
  RequestIntegrityTokenContinuation continuation
)
```
Requests an integrity token using a [RequestTokenData](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/request-token-data#structgoogle_1_1play_1_1integrity_1_1_request_token_data) obtained from a successful [PrepareIntegrityToken](https://developer.android.com/games/playgames/native-pc/reference/class/google/play/integrity/integrity-client#classgoogle_1_1play_1_1integrity_1_1_integrity_client_1a16b2300dfd23a2cbf3096e893f70a273) call.

Integrity tokens are a mechanism for your application to verify the device is not tampered with. For example, your backend server can use the integrity token to verify:

- Genuine device: Determine whether your application is running on a genuine device that contains a genuine instance of Google Play Games for PC and not tampered with.

<br />

When you're checking a user action in your app with the Play Integrity API, you can leverage the [RequestIntegrityTokenParams::request_hash](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/request-integrity-token-params#structgoogle_1_1play_1_1integrity_1_1_request_integrity_token_params_1aa68139c18e6b5a565e04802f87a2cd19) field to mitigate against tampering attacks.

For example, a game may want to report the player's score to the game's backend server, and your server wants to ensure this score has not been tampered with by a proxy server. The Play Integrity API returns the value you set in this field, inside the signed integrity response. Without the requestHash, the integrity token will be bound only to the device, but not to the specific request, which opens up the possibility of attack.

To mitigate this when you request an integrity verdict:

- Compute a digest of all relevant request parameters (e.g. SHA256 of a stable request serialization) from the user action or server request that is happening.
- Set the [RequestIntegrityTokenParams::request_hash](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/request-integrity-token-params#structgoogle_1_1play_1_1integrity_1_1_request_integrity_token_params_1aa68139c18e6b5a565e04802f87a2cd19) field to the digest.

<br />

<br />

Details Parameters `params` Parameters containing the prepared [RequestTokenData](https://developer.android.com/games/playgames/native-pc/reference/struct/google/play/integrity/request-token-data#structgoogle_1_1play_1_1integrity_1_1_request_token_data) and integrity check request hash. `continuation` The async callback to return the data to.

### \~IntegrityClient

```
 ~IntegrityClient()
```