Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

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)):



Matt Milan

💻

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!