npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tokenized/cordova-plugin-attestation-tokens

v0.3.0

Published

Cordova plugin for obtaining attestation tokens from Firebase App Check

Downloads

27

Readme

Cordova Firebase App Check Plugin

A Cordova plugin for obtaining iOS/Android app attestation tokens (for attachment to JavaScript REST API requests) from Firebase App Check.

This plugin is currently in development, for use in an upcoming version of the Tokenized Mobile Authenticator App, and is not yet recommended for production use. Please bear with us as we work towards a production-ready v1.0.

  • On iOS, uses the App Attest service
  • On Android, uses Google Play Integrity
  • Can be set up to use the App Check debug provider for testing valid attestation tokens in development builds (see below)
  • Provides two simple async functions to the Cordova app:
    • token = await window.AttestationTokens.getToken(); gets you a standard attestation token (encoded as a string) that can be passed to your REST API in a header for verification (see the App Check docs for details). Call getToken() every time you make a REST API call – the Firebase SDK caches the current token and manages refreshing it efficiently.
    • token = await window.AttestationTokens.getLimitedUseToken(); gets you a single-use attestation token that can be “consumed” by your back end after verification. This gives you protection against replay attacks at the expense of extra network requests for every request client-side and on the back end. As explained in the Firebase docs, it should therefore only be used on particularly sensitive endpoints.

Setting up

Enable App Check in Firebase

You will need to have a Firebase project set up for your app (app IDs and signing certificates registered for the platforms you are targeting). Enable the App Check service in the Firebase console and register each of your apps correctly:

Install the plugin

cordova-plugin-attestation-tokens adds the App Check module of the Firebase SDK as a dependency to your app. The version used can be controlled by specifying a Firebase SDK version number, on Android this is a version of the Firebase Android BoM, and on iOS the version of the Firebase SDK Cocoapod. The plugin provides variables for these which you can override when you install it (these are the defaults):

cordova plugin add @tokenized/cordova-plugin-attestation-tokens \
  --variable ANDROID_FIREBASE_BOM_VERSION="32.1.1" \
  --variable IOS_FIREBASE_POD_VERSION="10.11.0"

Configure the Firebase SDK

At runtime, the Firebase SDK configures itself by reading information from a platform-specific resource file that you need to download from the Firebase console and tell Cordova to copy into the published app as a resource file:

For Android, download google-services.json and add it into the root directory of your Cordova project. Add this line to the <platform name="android"> section of your config.xml:

<resource-file src="google-services.json" target="app/google-services.json" />

For iOS, download GoogleService-Info.plist and add it into the root directory of your Cordova project. Add this line to the <platform name="ios"> section of your config.xml:

<resource-file src="GoogleService-Info.plist" />

Other Firebase plugins

cordova-plugin-attestation-tokens initializes the Firebase SDK as part of app startup. On iOS it needs to set up the App Check provider before the configure function of the SDK is called, so it needs to start up before any other plugins you have that use Firebase, and those plugins need to have code that only calls configure if the Firebase SDK has not already been initialized.

For example, in the Tokenized Authenticator app, we also use cordova-plugin-firebase-messaging for push notifications. To get it to co-exist with cordova-plugin-attestation-tokens, we ensure that the attestation plugin is first in the Cordova plugins list in our package.json, and that the two plugins are using the same versions of the Firebase SDK:

{
  ...
  "cordova": {
    ...
    "plugins": {
      ...
      "@tokenized/cordova-plugin-attestation-tokens": {
        "ANDROID_FIREBASE_BOM_VERSION": "32.1.1",
        "IOS_FIREBASE_POD_VERSION": "10.11.0"
      },
      "cordova-plugin-firebase-messaging": {
        "ANDROID_FIREBASE_BOM_VERSION": "32.1.1",
        "IOS_FIREBASE_POD_VERSION": "10.11.0"
      },
      ...
    }
  }
  ...
}

(Note that after changing the order in package.json, you’ll need to completely remove the Cordova build dirs platforms/ and plugins/ and re-run cordova prepare.)

Attestation tokens in development builds

In the standard production setup documented above, valid attestation tokens can only be obtained when:

  • (For iOS builds): the app is signed by Apple via the App Store or TestFlight, and is running on a physical iOS device.
  • (For Android builds): the app is signed by Google via the Play Store, and is running on an Android device with Google Play Services.

However, in your local development builds, you can configure the plugin to use the App Check debug provider, and by registering a secret “debug token” (generated on your real/simulated test device) with the App Check console, you can obtain valid attestation tokens that verify when checked by your back end.

To indicate to the Cordova build process that you want to use the App Check debug provider, set the environment variable USE_DEBUG_APP_CHECK=true during cordova prepare. For convenience, we recommend setting up scripts for preparing builds in your package.json, something like this:

{
  "scripts": {
    ...
    "prepare-debug-android": "npm run make-www-debug && cross-env USE_DEBUG_APP_CHECK=true cordova prepare android",
    "prepare-debug-ios": "npm run make-www-debug && cross-env USE_DEBUG_APP_CHECK=true cordova prepare ios",
    "prepare-release-android": "npm run make-www-release && cordova prepare android",
    "prepare-release-ios": "npm run make-www-release && cordova prepare ios",
    ...
  }
}

The first time you run your development build on a new device, the debug provider will generate (and remember) a debug token and print it to the console, which you must register in the App Check console to authorize attestation. Note that on iOS, you also need to set the launch argument -FIRDebugEnabled in Xcode to see the debug token in the console. Refer to the debug provider documentation for iOS and Android for more information.

Note that cordova-plugin-attestation-tokens does not support the use of a CI debug token generated in the App Check console.

License

The project is MIT licensed.