Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattmilan-dev/capacitor-firebase-appcheck
Integrates native AppCheck functionality with CapacitorJS Hybrid Applications
https://github.com/mattmilan-dev/capacitor-firebase-appcheck
Last synced: about 2 months ago
JSON representation
Integrates native AppCheck functionality with CapacitorJS Hybrid Applications
- Host: GitHub
- URL: https://github.com/mattmilan-dev/capacitor-firebase-appcheck
- Owner: mattmilan-dev
- Created: 2021-08-04T22:21:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-09T20:31:02.000Z (over 3 years ago)
- Last Synced: 2024-10-17T06:57:29.184Z (3 months ago)
- Language: Java
- Size: 439 KB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
- awesome-capacitor - AppCheck - Allows usage of native AppCheck tokens. (Other plugins)
README
# capacitor-firebase-appcheck
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors-)
Allows usage of native AppCheck tokens in a Capacitor Hybrid application.
From the [Firebase Docs](https://firebase.google.com/docs/app-check):
>App Check works alongside other Firebase services to help protect your backend resources from abuse, such as billing fraud or phishing.## Install
```bash
npm install capacitor-firebase-appcheck
npx cap sync
```### Prereqs
You must enable AppCheck within your Firebase Project before installing this plugin. The location for both iOS and Android is the same, but the requirements for both are slightly different. See below for getting AppCheck set
up in your console (note, you only need to follow step one as this plugin takes the place of everything after):[Set up AppCheck on iOS with AppAttest (>iOS 14)](https://firebase.google.com/docs/app-check/ios/app-attest-provider#project-setup)
[Set up AppCheck on iOS with DeviceCheck ( {
// get the token from native
const { token, exp: expTimeMillis } = await AppCheck.getAppCheckToken();return {
token,
expireTimeMillis
}
}
}// activate appcheck [set true to refresh the token automatically on expiry]
firebase.appCheck().activate(appCheckCustomProvider, true);} catch (err) {
// log any errors
console.error(err);
}
```## API
- [capacitor-firebase-appcheck](#capacitor-firebase-appcheck)
- [Install](#install)
- [Prereqs](#prereqs)
- [iOS](#ios)
- [Android](#android)
- [Usage](#usage)
- [API](#api)
- [initialize(...)](#initialize)
- [getAppCheckToken()](#getappchecktoken)
- [Interfaces](#interfaces)
- [InitializationOptions](#initializationoptions)
- [AppCheckToken](#appchecktoken)
- [Contributors ✨](#contributors-)### initialize(...)
```typescript
initialize(options?: InitializationOptions | undefined) => Promise
```A method to initialise the AppCheck plugin. This must be called once and once only before
calling any other method. Returns true on success or false on failure. Check native logs to
see the actual problem.| Param | Type |
| ------------- | ----------------------------------------------------------------------- |
| **`options`** |InitializationOptions
|**Returns:**
boolean
**Since:** 1.0.0
--------------------
### getAppCheckToken()
```typescript
getAppCheckToken() => Promise
```Get's the native AppCheck token from AppAttest/DeviceCheck on iOS[>=14/<14] or SafetyNet on Android.
**Returns:**
Promise\<AppCheckToken\>
**Since:** 1.0.0
--------------------
### Interfaces
#### InitializationOptions
| Prop | Type | Description | Since |
| ----------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`debug`** |boolean
| If debug is enabled, the native environment will log debug creds and use debug mode. Intended to be used with staging or development environmnets only. Do not set this to TRUE in production. | 1.0.0 |#### AppCheckToken
| Prop | Type | Description | Since |
| ---- | ---- | ----------- | ----- |
| **`token`** |string
| The token provided by the native environment to be sent to firebase. | 1.0.0 |
| **`exp`** |number
| The expiration date of the token in milliseconds since epoch [Unix time] | 1.0.0 |## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!