Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(firebase_installations): initial Firebase Installations release #7377

Merged
merged 56 commits into from Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
93c655b
chore: setup firebase_installations
Ehesp Nov 16, 2021
69234eb
chore: firebase_installations class
Ehesp Nov 16, 2021
893b21a
chore: setup firebase_installations_platform_interface
Ehesp Nov 16, 2021
7056c8d
chore: firebase_installations_platform_interface logic
Ehesp Nov 16, 2021
0edd8a4
chore: setup firebase_installations_web
Ehesp Nov 16, 2021
bec45f1
chore: firebase_installations_web implementation
Ehesp Nov 16, 2021
0671055
feat: Android implementation
pr-Mais Nov 25, 2021
cd01e2e
feat: initial iOS implementation
pr-Mais Nov 29, 2021
65d951b
chore: add documentation
Ehesp Nov 30, 2021
7650154
chore: add version
Ehesp Nov 30, 2021
7125740
feat: idTokenChanged event channel
pr-Mais Nov 30, 2021
67e2e02
feat: example app enhancments
pr-Mais Nov 30, 2021
01e15d9
feat: iOS error handling
pr-Mais Dec 1, 2021
687fb9d
chore: remove Android dev logs
pr-Mais Dec 1, 2021
c1ac3e7
feat: fix eventChannel iOS implementation
pr-Mais Dec 1, 2021
936e84e
fix: web registration & config
pr-Mais Dec 1, 2021
edda52e
teat: e2e tests
pr-Mais Dec 1, 2021
dfaf199
chore: iOS example firebase service file reference
pr-Mais Dec 1, 2021
28046a5
chore: update auth token on idTokenChanged example app
pr-Mais Dec 1, 2021
bcc491c
test: adding github workflow
pr-Mais Dec 1, 2021
0dff9d1
chore: fix web drive tests
pr-Mais Dec 1, 2021
5c9daa0
test: adding unit tests
pr-Mais Dec 2, 2021
2474cf7
chore: run format
pr-Mais Dec 2, 2021
68ebc09
chore: experimenting test on CI
pr-Mais Dec 2, 2021
d64351b
feat: macos support
pr-Mais Dec 3, 2021
eabd1fe
feat: github macos workflow
pr-Mais Dec 3, 2021
afb189f
fix: iOS failing
pr-Mais Dec 3, 2021
0f91949
chore: macOS/iOS conditional imports
pr-Mais Dec 3, 2021
997b69d
chore: macOS linked files
pr-Mais Dec 3, 2021
523a121
chore: fix format and analyze
pr-Mais Dec 3, 2021
fe62a78
Merge branch 'dev' of https://github.com/FirebaseExtended/flutterfire…
pr-Mais Dec 3, 2021
baa121d
chore: typo
pr-Mais Dec 3, 2021
2a1fda8
chore: macos platform version
pr-Mais Dec 3, 2021
ac86593
chore: typo
pr-Mais Dec 3, 2021
54f9fba
chore: changelog
pr-Mais Dec 3, 2021
14abb72
chore: license
pr-Mais Dec 3, 2021
e84ab30
chore: typo
pr-Mais Dec 4, 2021
5c785fd
chore: commit macos podfile
pr-Mais Dec 4, 2021
4889ce4
Merge branch 'dev' of https://github.com/FirebaseExtended/flutterfire…
pr-Mais Dec 4, 2021
a457f81
chore: update README
pr-Mais Dec 4, 2021
f6a31f9
chore: exaample app enhancment
pr-Mais Dec 4, 2021
befb6b2
Revert "chore: fix format and analyze"
pr-Mais Dec 4, 2021
37718c9
Revert "chore: run format"
pr-Mais Dec 4, 2021
9fedcf2
chore: format
pr-Mais Dec 4, 2021
24d6f56
chore(installations): rename platform interface file
pr-Mais Dec 4, 2021
f347ab3
docs: updating platfrom interface & web READMEs
pr-Mais Dec 4, 2021
f098ff0
feat: enable auto injection of web SDKs
pr-Mais Dec 4, 2021
9cf3537
chore: rename `idTokenChanges` to `idChanges`
pr-Mais Dec 4, 2021
1e3fad5
Merge branch 'dev' of https://github.com/FirebaseExtended/flutterfire…
Salakar Dec 6, 2021
9eb0353
cleanup
Salakar Dec 6, 2021
61938c3
ios cleanup
Salakar Dec 6, 2021
f8e2092
bump versions and fix symlink
Salakar Dec 6, 2021
88b28f4
fix macos podspec
Salakar Dec 6, 2021
0435886
Merge branch 'dev' into @ehesp/installations
russellwheatley Dec 6, 2021
0e8592a
-
Salakar Dec 6, 2021
0d03c4e
Merge branch '@ehesp/installations' of https://github.com/FirebaseExt…
Salakar Dec 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/firebase_installations.yaml
@@ -0,0 +1,80 @@
name: firebase_installations

on:
pull_request:
paths:
- 'packages/firebase_installations/**'
- '.github/workflows/firebase_installations.yaml'
push:
branches:
- master
paths-ignore:
- 'docs/**'
- '**.md'

env:
FLUTTERFIRE_PLUGIN_SCOPE: '*firebase_installations*'
FLUTTERFIRE_PLUGIN_SCOPE_EXAMPLE: '*firebase_installations_example*'

jobs:
android:
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: 'Install Flutter'
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: 'Install Tools'
run: ./.github/workflows/scripts/install-tools.sh
- name: 'Build Example'
run: ./.github/workflows/scripts/build-example.sh android
- name: 'Drive Example'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 28
arch: x86_64
# Firebase Core works without Google Play Services, so we don't use the `googleapis`
# emulator target as it's considerably slower on CI.
target: default
profile: Nexus 5X
script: ./.github/workflows/scripts/drive-example.sh android

apple:
runs-on: macos-latest
timeout-minutes: 35
steps:
- uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: 'Install Flutter'
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: 'Install Tools'
run: |
./.github/workflows/scripts/install-tools.sh
flutter config --enable-macos-desktop
- name: 'Build iOS Example'
run: ./.github/workflows/scripts/build-example.sh ios
- name: 'Drive iOS Example'
run: ./.github/workflows/scripts/drive-example.sh ios
- name: 'Build MacOS Example'
run: ./.github/workflows/scripts/build-example.sh macos
- name: 'Drive MacOS Example'
run: ./.github/workflows/scripts/drive-example.sh macos

web:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: 'Install Flutter'
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: 'Install Tools'
run: |
./.github/workflows/scripts/install-tools.sh
flutter config --enable-web
- name: 'Drive Example'
run: ./.github/workflows/scripts/drive-example.sh web
70 changes: 70 additions & 0 deletions docs/installations/overview.mdx
@@ -0,0 +1,70 @@
---
title: Firebase Installations
sidebar_label: Overview
---

## What does it do?

Firebase Installations is a service that allows you to manage the installation of your app on a user's device.
The Firebase installations service (FIS) provides a Firebase installation ID (FID) for each installed instance of a Firebase app.

Internally, the installation ID is used by the following Firebase Services:

- Firebase Cloud Messaging (FCM)
- Firebase In-App Messaging (FIAM)
- Firebase Performance Monitoring
- Firebase Predictions
- Google Analytics for Firebase
- Firebase Remote Config
- Firebase ML

Tpically, Firebase services use the Firebase installations service without requiring developers to interact directly with the FIS API. However, there are cases where app developers might want to directly call the FIS API, such as:

- To delete a Firebase installation and data tied to the installation.
- To retrieve identifiers (Firebase installation IDs) in order to target specific app installations.
- To retrieve installation auth tokens to authenticate Firebase installations.

## Installation

Add the `firebase_installations` dependency to your projects `pubspec.yaml` file:

```yaml {5} title="pubspec.yaml"
dependencies:
flutter:
sdk: flutter
firebase_core: "^{{ plugins.firebase_core_ns }}"
firebase_installations: "^{{ plugins.firebase_installations_ns }}"
```

### 2. Download dependency

```
$ flutter pub get
```

### 3. (Web Only) Add the SDK

If using FlutterFire on the web, add the `firebase-installations` JavaScript SDK to your `index.html` file:

```html {5} title="web/index.html"
<html>
...
<body>
<script src="https://www.gstatic.com/firebasejs/{{ web.firebase_cdn }}/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/{{ web.firebase_cdn }}/firebase-installations.js"></script>
</body>
</html>
```

### 4. Rebuild your app

Once complete, rebuild your Flutter application:

```bash
$ flutter run
```

## Next Steps

Once installed, you're ready to start using Firebase Installations in your Flutter Project. View the
[Usage documentation](./usage.mdx) to get started.
108 changes: 108 additions & 0 deletions docs/installations/usage.mdx
@@ -0,0 +1,108 @@
---
title: Firebase Installations
sidebar_label: Usage
---

To start using the Firebase Installations package within your project, import it at the top of your project files:

```dart
import 'package:firebase_installations/firebase_installations.dart';
```

Before using Firebase Installations, you must first have ensured you have [initialized FlutterFire](../overview.mdx#initializing-flutterfire).

To create a new Installations instance, call the [`instance`](!firebase_installations.FirebaseInstallations.instance) getter on
[`FirebaseInstallations`](!firebase_installations.FirebaseInstallations):

```dart
FirebaseInstallations installations = FirebaseInstallations.instance;
```

By default, this allows you to interact with Installations using the default Firebase App used whilst installing
FlutterFire on your platform. If however you'd like to use a secondary Firebase App, use the `instanceFor` method:

```dart
FirebaseApp secondaryApp = Firebase.app('SecondaryApp');
FirebaseInstallations installations = FirebaseInstallations.instanceFor(app: secondaryApp);
```

## Delete a Firebase installation

Data tied to a Firebase installation is generally not personally identifying. Still, it can be helpful to give users an option to manage and delete this data.

Firebase installation IDs are different for every installation of every application; different applications on the same device have different Firebase installation IDs.
Firebase installation IDs identify app installations and data tied to those app installations.

When you delete an installation ID, the data tied to that installation ID is removed from live and backup systems of all Firebase services that use Firebase installation
IDs to identify installations within 180 days. This process is described at a high level in Google’s [statement on deletion and retention](https://policies.google.com/technologies/retention).

Unless you disable all FID-generating services in your app, FIS creates a new ID within a few days. Firebase considers the newly-created ID to be a new Firebase installation,
and doesn't associate it with the previous ID or data in any way.

To delete an FID, call the `delete` method on the [`FirebaseInstallations`](!firebase_installations.FirebaseInstallations) instance:

```dart
await FirebaseInstallations.instance.delete();
```

## Retrieve client identifers

If you have a requirement to identify particular installations of your app, you can do so by retrieving the Firebase installation ID.
For example, to perform testing during Firebase In-App Messaging development, you can identify and target the correct test device using
its Firebase installation ID.

To get the Firebase installation ID, call the `getId` method on the [`FirebaseInstallations`](!firebase_installations.FirebaseInstallations) instance:

```dart
String id = await FirebaseInstallations.instance.getId();
```

## Retrieve installation auth tokens

Firebase services can authenticate Firebase installations with auth tokens retrieved from FIS. For example, when designing A/B tests for Remote Config,
you can authenticate a targeted test device using an installation auth token.

An installation auth token is a short-lived bearer token in JSON web token (JWT) format containing the following information for an installation:

- The Firebase installation ID
- The associated project (projectNumber)
- The associated Firebase application ID (appId)
- The token's expiration date

An installation auth token cannot be revoked, and remains valid until its expiration date. The default token lifetime is one week.

To retrieve an installation auth token:

```dart
String token = await FirebaseInstallations.instance.getToken();
```

Optionally, you can force a token refresh when called:

```dart
String token = await FirebaseInstallations.instance.getToken(true);
```

## Monitor the Firebase installation ID lifecycle

During the normal operation of an app, Firebase installation IDs (FIDs) don't require special monitoring. However, apps that explictly retrieve and
use FIDs should add logic to monitor the potential deletion or rotation of the FID. Here are some cases where FIDs could be deleted or rotated:

- Uninstallation or reinstallation of the app, for instance when an end user installs on a new device.
- The end user clears the cache of the app or the device.
- FID deletion is triggered in the backend due to app inactivity (currently the threshold for this is 270 days of inactivity).

When apps experience FID rotation or deletion in these kinds of cases, they are assigned a new FID. Also, the installation auth token associated with
a deleted FID is deleted, regardless of its own maturity, and is replaced with a new installation auth token.

Apps can monitor these changes and respond accordingly.

To monitor the FID token, listen to the `Stream` returned from the `idTokenChanges` getter:

```dart
FirebaseInstallations.instance.idTokenChanges.listen((token) {
print('FID token: $token');
});
```


4 changes: 4 additions & 0 deletions docs/sidebars.js
Expand Up @@ -67,6 +67,10 @@ module.exports = {
toReferenceAPI("cloud_functions"),
toGithubExample("cloud_functions"),
],
Installations: [
"installations/overview",
"installations/usage",
],
"Cloud Messaging": [
"messaging/overview",
"messaging/usage",
Expand Down
13 changes: 7 additions & 6 deletions docs/versions.js
Expand Up @@ -31,16 +31,17 @@ export default {
firebase_performance_ns: PUB_NS_FIREBASE_PERFORMANCE,
firebase_remote_config: PUB_FIREBASE_REMOTE_CONFIG,
firebase_remote_config_ns: PUB_NS_FIREBASE_REMOTE_CONFIG,
google_sign_in: "^4.4.4",
firebase_installations_ns: PUB_NS_FIREBASE_INSTALLATIONS,
google_sign_in: '^4.4.4',
},
android: {
google_services: "4.3.8", // com.google.gms:google-services
google_services: '4.3.8', // com.google.gms:google-services
},
web: {
firebase_cdn: "8.6.1", // https://firebase.google.com/support/release-notes/js
firebase_cdn: '8.6.1', // https://firebase.google.com/support/release-notes/js
},
external: {
google_sign_in: "^4.5.1",
flutter_facebook_auth: "^3.5.0",
}
google_sign_in: '^4.5.1',
flutter_facebook_auth: '^3.5.0',
},
};
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
10 changes: 10 additions & 0 deletions packages/firebase_installations/firebase_installations/.metadata
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 18116933e77adc82f80866c928266a5b4f1ed645
channel: stable

project_type: plugin
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
27 changes: 27 additions & 0 deletions packages/firebase_installations/firebase_installations/LICENSE
@@ -0,0 +1,27 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 changes: 23 additions & 0 deletions packages/firebase_installations/firebase_installations/README.md
@@ -0,0 +1,23 @@
# Firebase Installations Plugin for Flutter

A Flutter plugin to use the [Firebase Installations API](https://firebase.google.com/docs/projects/manage-installations).

[![pub package](https://img.shields.io/pub/v/firebase_installations.svg)](https://pub.dev/packages/firebase_installations)

## Getting Started

To get started with Firebase Installations for Flutter, please [see the documentation](https://firebase.flutter.dev/docs/installations/overview).

## Usage

To use this plugin, please visit the [Installations Usage documentation](https://firebase.flutter.dev/docs/installations/usage)

## Issues and feedback

Please file FlutterFire specific issues, bugs, or feature requests in our [issue tracker](https://github.com/FirebaseExtended/flutterfire/issues/new).

Plugin issues that are not specific to FlutterFire can be filed in the [Flutter issue tracker](https://github.com/flutter/flutter/issues/new).

To contribute a change to this plugin,
please review our [contribution guide](https://github.com/FirebaseExtended/flutterfire/blob/master/CONTRIBUTING.md)
and open a [pull request](https://github.com/FirebaseExtended/flutterfire/pulls).
@@ -0,0 +1,8 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures