@capacitor-community/play-integrity
The Play Integrity API is used to verify that your app is a Genuine App Binary that has not been modified compared to what is available on the Play Store. It validates that the current user account is licensed (the user that installed or paid for your app) and whether the app is free from known malware.
This plugin calls the Play Integrity API requestIntegrityToken
method which returns a token that your App's server must verify with Google Play Servers.
The call requestIntegrityToken
will return a token
on success which you must send to your backend for verification. See Google's Docs on this.
npm install @capacitor-community/play-integrity
npx cap sync
import { PlayIntegrity } from '@capacitor-community/play-integrity';
...
try {
// Nonce: See https://developer.android.com/google/play/integrity/classic
// googleCloudProjectNumber: leave as 0 for the default for the application
// or get from https://console.firebase.google.com/ Project Settings > General
const result = await PlayIntegrity.requestIntegrityToken({
nonce: nonce,
googleCloudProjectNumber: 0
});
// Use result.token and decrypt and verify the integrity verdict
// https://developer.android.com/google/play/integrity/classic#decrypt-verify
console.log(`Play Integrity Result`, result);
} catch (err) {
// Recommendation: Report to backend and exit the application
}
requestIntegrityToken(options: { nonce: string; googleCloudProjectNumber: number; }) => Promise<{ token: string; }>
Param | Type |
---|---|
options |
{ nonce: string; googleCloudProjectNumber: number; } |
Returns: Promise<{ token: string; }>
The following errors can occur and should be handled.
Error: -1: Integrity API error (-1): Integrity API is not available.
Integrity API is not enabled, or the Play Store version might be old.
Recommended actions:
1) Make sure that Integrity API is enabled in Google Play Console.
2) Ask the user to update Play Store.
(https://developer.android.com/google/play/integrity/reference/com/google/android/play/core/integrity/model/IntegrityErrorCode.html#API_NOT_AVAILABLE).
Play Services not found