@capacitor-community/play-integrity
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published


PLAY INTEGRITY

@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.

Install

npm install @capacitor-community/play-integrity
npx cap sync

Usage

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
    }

API

requestIntegrityToken(...)

requestIntegrityToken(options: { nonce: string; googleCloudProjectNumber: number; }) => Promise<{ token: string; }>
Param Type
options { nonce: string; googleCloudProjectNumber: number; }

Returns: Promise<{ token: string; }>


Errors

The following errors can occur and should be handled.

Integrity API not available

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

Play Services not found

Package Sidebar

Install

npm i @capacitor-community/play-integrity

Weekly Downloads

13

Version

6.0.0

License

MIT

Unpacked Size

21.3 kB

Total Files

25

Last publish

Collaborators

  • ionicjs
  • danielprrazevedo
  • nkalupahana
  • dtarnawsky
  • ryaa
  • dallasjames
  • tafelnl
  • thegnuu
  • pbowyer
  • capcombot
  • jcesarmobile
  • maxlynch
  • mhartington
  • it_mike_s
  • byrds
  • rdlabo
  • priyankpatel
  • dwieeb
  • stewan
  • arielhernandezmusa
  • jeepq
  • start9keagan
  • boosten
  • nklayman
  • ihadeed
  • ckgaparajita
  • jpender
  • nhyatt
  • pwespi
  • epicshaggy
  • thomasvidas
  • robingenz
  • diachedelic
  • johnborges
  • tobyas
  • elylucas
  • larsmikkelsen
  • giodimiliaionic
  • brownoxford
  • mrbatista
  • bazuka5801
  • hemang