Skip to content

Commit 8f8c0a1

Browse files
committed
fix(appcheck): add new appCheck package for debug mode
feat: allow custom app check providers
1 parent 4378cfb commit 8f8c0a1

File tree

107 files changed

+2833
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+2833
-101
lines changed

Diff for: README.md

+17-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1-
# @nativescript/\* plugins
2-
3-
```
4-
npm run setup
5-
npm start
6-
```
7-
8-
- [@nativescript/firebase-admob](packages/firebase-admob/README.md)
9-
- [@nativescript/firebase-analytics](packages/firebase-analytics/README.md)
10-
- [@nativescript/firebase-app-check](packages/firebase-app-check/README.md)
11-
- [@nativescript/firebase-auth](packages/firebase-auth/README.md)
12-
- [@nativescript/firebase-core](packages/firebase-core/README.md)
13-
- [@nativescript/firebase-crashlytics](packages/firebase-crashlytics/README.md)
14-
- [@nativescript/firebase-database](packages/firebase-database/README.md)
15-
- [@nativescript/firebase-dynamic-links](packages/firebase-dynamic-links/README.md)
16-
- [@nativescript/firebase-firestore](packages/firebase-firestore/README.md)
17-
- [@nativescript/firebase-functions](packages/firebase-functions/README.md)
18-
- [@nativescript/firebase-in-app-messaging](packages/firebase-in-app-messaging/README.md)
19-
- [@nativescript/firebase-installations](packages/firebase-installations/README.md)
20-
- [@nativescript/firebase-messaging](packages/firebase-messaging/README.md)
21-
- [@nativescript/firebase-performance](packages/firebase-performance/README.md)
22-
- [@nativescript/firebase-remote-config](packages/firebase-remote-config/README.md)
23-
- [@nativescript/firebase-storage](packages/firebase-storage/README.md)
1+
- @nativescript/firebase-admob
2+
- @nativescript/firebase-analytics
3+
- @nativescript/firebase-app-check
4+
- @nativescript/firebase-app-check-debug
5+
- @nativescript/firebase-auth
6+
- @nativescript/firebase-core
7+
- @nativescript/firebase-crashlytics
8+
- @nativescript/firebase-database
9+
- @nativescript/firebase-dynamic-links
10+
- @nativescript/firebase-firestore
11+
- @nativescript/firebase-functions
12+
- @nativescript/firebase-in-app-messaging
13+
- @nativescript/firebase-installations
14+
- @nativescript/firebase-messaging
15+
- @nativescript/firebase-performance
16+
- @nativescript/firebase-remote-config
17+
- @nativescript/firebase-storage
2418

2519
# How to use?
2620

Diff for: apps/demo-angular/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"@nativescript/firebase-installations": "file:../../dist/packages/firebase-installations",
1818
"@nativescript/firebase-dynamic-links": "file:../../dist/packages/firebase-dynamic-links",
1919
"@nativescript/firebase-messaging": "file:../../dist/packages/firebase-messaging",
20-
"@nativescript/firebase-functions": "file:../../dist/packages/firebase-functions"
20+
"@nativescript/firebase-functions": "file:../../dist/packages/firebase-functions",
21+
"@nativescript/firebase-app-check-debug": "file:../../dist/packages/firebase-app-check-debug"
2122
},
2223
"devDependencies": {
2324
"@nativescript/android": "8.0.0",

Diff for: apps/demo-angular/src/app-routing.module.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const routes: Routes = [
1010
{ path: 'firebase-admob', loadChildren: () => import('./plugin-demos/firebase-admob.module').then(m => m.FirebaseAdmobModule) },
1111
{ path: 'firebase-analytics', loadChildren: () => import('./plugin-demos/firebase-analytics.module').then(m => m.FirebaseAnalyticsModule) },
1212
{ path: 'firebase-app-check', loadChildren: () => import('./plugin-demos/firebase-app-check.module').then(m => m.FirebaseAppCheckModule) },
13+
{ path: 'firebase-app-check-debug', loadChildren: () => import('./plugin-demos/firebase-app-check-debug.module').then(m => m.FirebaseAppCheckDebugModule) },
1314
{ path: 'firebase-auth', loadChildren: () => import('./plugin-demos/firebase-auth.module').then(m => m.FirebaseAuthModule) },
1415
{ path: 'firebase-core', loadChildren: () => import('./plugin-demos/firebase-core.module').then(m => m.FirebaseCoreModule) },
1516
{ path: 'firebase-crashlytics', loadChildren: () => import('./plugin-demos/firebase-crashlytics.module').then(m => m.FirebaseCrashlyticsModule) },

Diff for: apps/demo-angular/src/home.component.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export class HomeComponent {
1515
{
1616
name: 'firebase-app-check'
1717
},
18+
{
19+
name: 'firebase-app-check-debug'
20+
},
1821
{
1922
name: 'firebase-auth'
2023
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ActionBar title="firebase-app-check-debug" class="action-bar"> </ActionBar>
2+
<StackLayout class="p-20">
3+
<ScrollView class="h-full">
4+
<StackLayout>
5+
<Button text="Test firebase-app-check-debug" (tap)="demoShared.testIt()" class="btn btn-primary"></Button>
6+
</StackLayout>
7+
</ScrollView>
8+
</StackLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component, NgZone } from '@angular/core';
2+
import { DemoSharedFirebaseAppCheckDebug } from '@demo/shared';
3+
import { } from '@nativescript/firebase-app-check-debug';
4+
5+
@Component({
6+
selector: 'demo-firebase-app-check-debug',
7+
templateUrl: 'firebase-app-check-debug.component.html',
8+
})
9+
export class FirebaseAppCheckDebugComponent {
10+
11+
demoShared: DemoSharedFirebaseAppCheckDebug;
12+
13+
constructor(private _ngZone: NgZone) {}
14+
15+
ngOnInit() {
16+
this.demoShared = new DemoSharedFirebaseAppCheckDebug();
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
2+
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular';
3+
import { FirebaseAppCheckDebugComponent } from './firebase-app-check-debug.component';
4+
5+
@NgModule({
6+
imports: [NativeScriptCommonModule, NativeScriptRouterModule.forChild([{ path: '', component: FirebaseAppCheckDebugComponent }])],
7+
declarations: [FirebaseAppCheckDebugComponent],
8+
schemas: [ NO_ERRORS_SCHEMA]
9+
})
10+
export class FirebaseAppCheckDebugModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<Page>
3+
<ActionBar>
4+
<Label text="firebase-app-check-debug"/>
5+
</ActionBar>
6+
7+
<GridLayout>
8+
<Button class="info" :text="message"/>
9+
</GridLayout>
10+
</Page>
11+
</template>
12+
13+
<script lang="ts">
14+
import Vue from "nativescript-vue";
15+
import { DemoSharedFirebaseAppCheckDebug } from '@demo/shared';
16+
import { } from '@nativescript/firebase-app-check-debug';
17+
18+
export default Vue.extend({
19+
computed: {
20+
message() {
21+
return "Test firebase-app-check-debug";
22+
}
23+
}
24+
});
25+
</script>
26+
27+
<style scoped lang="scss">
28+
29+
.info {
30+
font-size: 20;
31+
horizontal-align: center;
32+
vertical-align: center;
33+
}
34+
</style>

Diff for: apps/demo-vue/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"@nativescript/firebase-messaging": "file:../../packages/firebase-messaging",
1919
"@nativescript/firebase-performance": "file:../../packages/firebase-performance",
2020
"@nativescript/firebase-remote-config": "file:../../packages/firebase-remote-config",
21-
"@nativescript/firebase-storage": "file:../../packages/firebase-storage"
21+
"@nativescript/firebase-storage": "file:../../packages/firebase-storage",
22+
"@nativescript/firebase-app-check-debug": "file:../../packages/firebase-app-check-debug"
2223
},
2324
"devDependencies": {
2425
"@nativescript/android": "8.0.0",

Diff for: apps/demo/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
"@nativescript/firebase-performance": "file:../../packages/firebase-performance",
2222
"@nativescript/firebase-remote-config": "file:../../packages/firebase-remote-config",
2323
"@nativescript/firebase-storage": "file:../../packages/firebase-storage",
24-
"@nativescript/google-signin": "^1.0.0-alpha.9"
24+
"@nativescript/google-signin": "^1.0.0-alpha.9",
25+
"@nativescript/firebase-app-check-debug": "file:../../packages/firebase-app-check-debug"
2526
},
2627
"devDependencies": {
2728
"@nativescript/android": "^8.2.0-alpha.11",
2829
"@nativescript/ios": "8.1.0"
2930
}
30-
}
31+
}

Diff for: apps/demo/src/app.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ import '@nativescript/firebase-storage';
1717

1818
import { Admob } from '@nativescript/firebase-admob';
1919

20-
firebase().initializeApp();
20+
import { AppCheck } from '@nativescript/firebase-app-check-debug';
21+
22+
AppCheck.setProviderFactory();
23+
24+
firebase().initializeApp().then(app =>{
25+
firebase().appCheck().activate(true);
26+
})
2127

2228
Admob.init();
2329

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Observable, EventData, Page } from '@nativescript/core';
2+
import { DemoSharedFirebaseAppCheckDebug } from '@demo/shared';
3+
import { } from '@nativescript/firebase-app-check-debug';
4+
5+
export function navigatingTo(args: EventData) {
6+
const page = <Page>args.object;
7+
page.bindingContext = new DemoModel();
8+
}
9+
10+
export class DemoModel extends DemoSharedFirebaseAppCheckDebug {
11+
12+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
2+
<Page.actionBar>
3+
<ActionBar title="firebase-app-check-debug" icon="" class="action-bar">
4+
</ActionBar>
5+
</Page.actionBar>
6+
<StackLayout class="p-20">
7+
<ScrollView class="h-full">
8+
<StackLayout>
9+
<Button text="Test firebase-app-check-debug" tap="{{ testIt }}" class="btn btn-primary"/>
10+
11+
</StackLayout>
12+
</ScrollView>
13+
</StackLayout>
14+
</Page>

Diff for: nx.json

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
},
7474
"demo-vue": {
7575
"tags": []
76+
},
77+
"firebase-app-check-debug": {
78+
"tags": []
7679
}
7780
},
7881
"workspaceLayout": {

Diff for: packages/firebase-admob/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-admob",
3-
"version": "1.0.6",
3+
"version": "1.1.0",
44
"description": "NativeScript Firebase - Admob",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-analytics/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/firebase-analytics",
3-
"version": "1.0.6",
3+
"version": "1.1.0",
44
"description": "NativeScript Firebase - Analytics",
55
"main": "index",
66
"typings": "index.d.ts",

Diff for: packages/firebase-app-check-debug/README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# @nativescript/firebase-app-check-debug
2+
3+
```cli
4+
ns plugin add @nativescript/firebase-app-check-debug
5+
```
6+
7+
> **Warning**: The debug provider allows access to your Firebase resources from unverified devices. Don't use the debug provider in production builds of your app, and don't share your debug builds with untrusted parties.
8+
9+
10+
11+
> **Note**: (iOS) App Check requires you set the minimum iOS Deployment version in ios/Podfile to 11.0 or greater.
12+
13+
14+
### What does it do
15+
16+
App Check works alongside other Firebase services to help protect your backend resources from abuse, such as billing fraud or phishing. With App Check, devices running your app will use an app or device attestation provider that attests to one or both of the following:
17+
18+
Requests originate from your authentic app
19+
Requests originate from an authentic, untampered device
20+
This attestation is attached to every request your app makes to your Firebase backend resources.
21+
22+
[![image](https://img.youtube.com/vi/Fjj4fmr2t04/hqdefault.jpg)](https://www.youtube.com/watch?v=Fjj4fmr2t04)
23+
24+
This App Check module has built-in support for using the following services as attestation providers:
25+
26+
DeviceCheck on iOS
27+
SafetyNet on Android
28+
App Check currently works with the following Firebase products:
29+
30+
Realtime Database
31+
Cloud Storage
32+
Cloud Functions (callable functions)
33+
The [official Firebase App Check documentation](https://firebase.google.com/docs/app-check) has more information, including about the iOS AppAttest provider, and testing/ CI integration, it is worth a read.
34+
35+
## Usage
36+
37+
### Activate
38+
39+
40+
41+
```ts
42+
import { firebase } from '@nativescript/firebase-core';
43+
import { AppCheck } from '@nativescript/firebase-app-check-debug';
44+
45+
AppCheck.setProviderFactory(); // call before the fb app is initialized
46+
firebase.initializeApp()
47+
.then(app =>{
48+
firebase().appCheck().activate(true);
49+
})
50+
51+
52+
```
53+
54+
The only configuration possible is the token auto refresh. When you call activate, the provider stays the same but the token auto refresh setting will be changed based on the argument provided.
55+
56+
You must call activate prior to calling any firebase back-end services for App Check to function.
57+
58+
59+
### Automatic Data Collection
60+
61+
App Check has an "tokenAutoRefreshEnabled" setting. This may cause App Check to attempt a remote App Check token fetch prior to user consent. In certain scenarios, like those that exist in GDPR-compliant apps running for the first time, this may be unwanted.
62+
63+
If unset, the "tokenAutoRefreshEnabled" setting will defer to the app's "automatic data collection" setting, which may be set in the Info.plist or AndroidManifest.xml
64+
65+
66+
### Using App Check tokens for non-firebase services
67+
68+
The [official documentation](https://firebase.google.com/docs/app-check/web/custom-resource) shows how to use getToken to access the current App Check token and then verify it in external services.
69+
70+
## License
71+
72+
Apache License Version 2.0

Diff for: packages/firebase-app-check-debug/common.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FirebaseApp } from '@nativescript/firebase-core';
2+
3+
export interface IAppCheck {
4+
app: FirebaseApp;
5+
activate(isTokenAutoRefreshEnabled: boolean);
6+
setTokenAutoRefreshEnabled(enabled: boolean);
7+
getToken(forceRefresh: boolean): Promise<IAppCheckToken>;
8+
}
9+
10+
export interface IAppCheckToken {
11+
readonly token: string;
12+
readonly expireTimeMillis: number;
13+
}

0 commit comments

Comments
 (0)