https://github.com/capacitor-community/play-integrity
A Capacitor plugin to use the Play Integrity API
https://github.com/capacitor-community/play-integrity
capacitor integrity play plugin
Last synced: 8 months ago
JSON representation
A Capacitor plugin to use the Play Integrity API
- Host: GitHub
- URL: https://github.com/capacitor-community/play-integrity
- Owner: capacitor-community
- Created: 2024-01-15T21:05:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-16T16:07:30.000Z (over 1 year ago)
- Last Synced: 2024-04-26T07:25:43.114Z (over 1 year ago)
- Topics: capacitor, integrity, play, plugin
- Language: Java
- Homepage:
- Size: 159 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
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`](https://developer.android.com/google/play/integrity/classic) 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](https://developer.android.com/google/play/integrity/classic#decrypt-verify).
## Install
```bash
npm install @capacitor-community/play-integrity
npx cap sync
```## Usage
```typescript
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)
### requestIntegrityToken(...)
```typescript
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
```