Skip to content

Commit c4b6684

Browse files
committed
feat: keyboardmanager and fingerprint auth
1 parent f7c7b57 commit c4b6684

29 files changed

+2975
-63
lines changed
Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,93 @@
11
import { Observable, EventData, Page } from '@nativescript/core';
2-
import {} from '@nativescript/fingerprint-auth';
2+
import { FingerprintAuth, BiometricIDAvailableResult } from '@nativescript/fingerprint-auth';
33

44
export function navigatingTo(args: EventData) {
55
const page = <Page>args.object;
66
page.bindingContext = new DemoModel();
77
}
88

99
export class DemoModel extends Observable {
10-
testIt() {
11-
// Test something here
10+
private fingerprintAuth: FingerprintAuth;
11+
public status: string = 'Tap a button below..';
12+
private static CONFIGURED_PASSWORD = 'MyPassword';
13+
14+
constructor() {
15+
super();
16+
this.fingerprintAuth = new FingerprintAuth();
17+
}
18+
19+
public doCheckAvailable(): void {
20+
this.fingerprintAuth
21+
.available()
22+
.then((result: BiometricIDAvailableResult) => {
23+
console.log('doCheckAvailable result: ' + JSON.stringify(result));
24+
this.set('status', 'Biometric ID available? - ' + (result.any ? (result.face ? 'Face' : 'Touch') : 'NO'));
25+
})
26+
.catch((err) => {
27+
console.log('doCheckAvailable error: ' + err);
28+
this.set('status', 'Error: ' + err);
29+
});
30+
}
31+
32+
public doCheckFingerprintsChanged(): void {
33+
this.fingerprintAuth.didFingerprintDatabaseChange().then((changed: boolean) => {
34+
this.set('status', 'Biometric ID changed? - ' + (changed ? 'YES' : 'NO'));
35+
});
36+
}
37+
38+
public doVerifyFingerprint(): void {
39+
this.fingerprintAuth
40+
.verifyFingerprint({
41+
title: 'Enter your password',
42+
message: 'Scan yer finger', // optional
43+
authenticationValidityDuration: 10, // Android
44+
})
45+
.then(() => this.set('status', 'Biometric ID / passcode OK'))
46+
.catch((err) => {
47+
alert({
48+
title: 'Biometric ID NOT OK / canceled',
49+
message: JSON.stringify(err),
50+
okButtonText: 'Mmkay',
51+
});
52+
});
53+
}
54+
55+
public doVerifyFingerprintWithCustomUI(): void {
56+
this.fingerprintAuth
57+
.verifyFingerprint({
58+
message: 'Scan yer finger', // optional
59+
useCustomAndroidUI: true, // Android
60+
})
61+
.then((enteredPassword?: string) => {
62+
if (enteredPassword === undefined) {
63+
this.set('status', 'Biometric ID OK');
64+
} else {
65+
// compare enteredPassword to the one the user previously configured for your app (which is not the users system password!)
66+
if (enteredPassword === DemoModel.CONFIGURED_PASSWORD) {
67+
this.set('status', 'Biometric ID OK, using password');
68+
} else {
69+
this.set('status', `Wrong password. Try '${DemoModel.CONFIGURED_PASSWORD}' 😉`);
70+
}
71+
}
72+
})
73+
.catch((err) => this.set('status', `Biometric ID NOT OK: " + ${JSON.stringify(err)}`));
74+
}
75+
76+
public doVerifyFingerprintWithCustomFallback(): void {
77+
this.fingerprintAuth
78+
.verifyFingerprintWithCustomFallback({
79+
message: 'Scan yer finger', // optional
80+
fallbackMessage: 'Enter PIN', // optional
81+
authenticationValidityDuration: 10, // Android
82+
})
83+
.then(() => this.set('status', 'Biometric ID OK'))
84+
.catch((error) => {
85+
this.set('status', 'Biometric ID NOT OK: ' + JSON.stringify(error));
86+
alert({
87+
title: 'Biometric ID NOT OK',
88+
message: error.code === -3 ? 'Show custom fallback' : error.message,
89+
okButtonText: 'Mmkay',
90+
});
91+
});
1292
}
1393
}
Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
1-
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
2-
<Page.actionBar>
3-
<ActionBar title="fingerprint-auth" 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 Plugin" tap="{{ testIt }}" class="btn btn-primary"/>
1+
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
2+
<TabView>
3+
<TabView.items>
4+
<TabViewItem title="Demo">
5+
<TabViewItem.view>
6+
<ScrollView>
7+
<StackLayout class="tab-content">
8+
<Label text="{{ status }}" class="status" textWrap="true" style="text-align: center"/>
9+
<Label text="Checking availability" class="title"/>
10+
<Button text="available?" tap="{{ doCheckAvailable }}" class="button" />
1011

12+
<Label text="Detect changes in the device biometric database. For best security you want to have the user reauth whenever this method returns true." textWrap="true"/>
13+
<Button text="Biometric ID changed?" tap="{{ doCheckFingerprintsChanged }}" class="button" />
14+
15+
<Label text="Scanning the fingerprint / face" class="title"/>
16+
<Label text="When scanning fails or is not possible, you can either use the built-in passcode fallback or handle it yourself (custom fallback)." textWrap="true"/>
17+
<Button text="verify with passcode fallback" tap="{{ doVerifyFingerprint }}" class="button" />
18+
<iOS>
19+
<Button text="verify with custom fallback" tap="{{ doVerifyFingerprintWithCustomFallback }}" class="button" />
20+
</iOS>
21+
<Android>
22+
<Label text="Note that this will fail if you previously cancelled authentication with the button above. Try reinstalling the app if funny things happen." textWrap="true"/>
23+
<Button text="verify with custom UI" tap="{{ doVerifyFingerprintWithCustomUI }}" class="button" />
24+
</Android>
25+
</StackLayout>
26+
</ScrollView>
27+
</TabViewItem.view>
28+
</TabViewItem>
29+
<TabViewItem title="About">
30+
<TabViewItem.view>
31+
<StackLayout class="tab-content">
32+
<Image margin="10" src="~/res/telerik-logo.png" />
33+
<Label text="Fingerprint Auth plugin demo" class="title"/>
34+
<Label text="The Fingerprint Auth allows you to use the fingerprint / face scanner of your mobile device." textWrap="true"/>
35+
<Label text=" "/>
36+
<!-- poor mans line break, lol -->
37+
<Label text="With this plugin you can replace traditional password / pincode login forms by a convenient and secure biometric authentication mechanism." textWrap="true"/>
1138
</StackLayout>
12-
</ScrollView>
13-
</StackLayout>
39+
</TabViewItem.view>
40+
</TabViewItem>
41+
</TabView.items>
42+
</TabView>
1443
</Page>

0 commit comments

Comments
 (0)