Skip to content

Commit

Permalink
feat: add enroll/authenticate example
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Oct 28, 2020
1 parent ee5f685 commit d37a501
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 112 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ buck-out/
ZoomAuthenticationHybrid.framework
app-token.json
license-key.json
device-key-identifier.json
171 changes: 82 additions & 89 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,137 +1,130 @@
import React from "react";
import React from 'react'
import {
Platform,
TouchableHighlight,
StyleSheet,
ScrollView,
View,
Text,
Image
} from "react-native";
Image,
} from 'react-native'

import Zoom from "react-native-facetec-zoom";
import ZOOM_APP_TOKEN from "./license-key";
import Zoom from 'react-native-facetec-zoom'
import deviceKeyIdentifier from './device-key-identifier'

Zoom.preload();
const BigText = ({ children, style }) => <Text style={[styles.bigText, style]}>{children}</Text>

const bigText = (text, style) => (
<Text style={[styles.bigText, style]}>{text}</Text>
);
const hugeText = (text, style) => (
<Text style={[styles.hugeText, style]}>{text}</Text>
);
const createButton = ({ text, ...props }) => (
const Button = ({ children, ...props }) => (
<TouchableHighlight {...props} style={styles.button}>
{hugeText(text, styles.buttonText)}
<Text style={[styles.hugeText, styles.buttonText]}>{children}</Text>
</TouchableHighlight>
);
)

const prettify = obj => (obj ? JSON.stringify(obj, null, 2) : "");
const prettify = (obj) => (obj ? JSON.stringify(obj, null, 2) : '')
// don't actually do this
const getFaceID = () => String(Math.random()).split('.')[1]

export default class App extends React.Component {
state = {};
verifyLiveness = async () => {
state = {}
init = async () => {
const { success, status } = await Zoom.initialize({
appToken: ZOOM_APP_TOKEN,
deviceKeyIdentifier,
showPreEnrollmentScreen: false,
showUserLockedScreen: false,
showRetryScreen: false,
topMargin: 200,
// sizeRatio: 0.7,
centerFrame: false
});
centerFrame: false,
returnBase64: false,
})

if (!success) {
// see constants.js SDKStatus for explanations of various
// reasons why initialize might not have gone through
throw new Error(`failed to init. SDK status: ${status}`);
throw new Error(`failed to init. SDK status: ${status}`)
}

this.initialized = true
}

enroll = async () => {
if (!this.initialized) await this.init()

const faceID = getFaceID()
this.setState({ faceID })

// launch Zoom's enrollment process
return Zoom.enroll({
id: faceID,
}).then(this.setResult, this.setError)
}

authenticate = async () => {
if (!this.initialized) await this.init()

// launch Zoom's enrollment process
return Zoom.authenticate({
id: this.state.faceID,
}).then(this.setResult, this.setError)
}

verifyLiveness = async () => {
if (!this.initialized) await this.init()

// launch Zoom's verification process
return await Zoom.verify({
// no options at this point
});
};
render = () => {
const button = createButton({
key: "button",
text: "Verify Liveness",
onPress: async () => {
try {
this.setState({
result: await this.verifyLiveness()
});
} catch (error) {
this.setState({ error });
}
}
});
let result = this.renderResult();
let error = this.state.error && (
<View>
{bigText("Error:")}
{this.renderError()}
</View>
);
return Zoom.verifyLiveness().then(this.setResult, this.setError)
}

setResult = (result) => this.setState({ result })
setError = (error) => this.setState({ error })

render = () => {
return (
<View style={styles.container}>
{bigText("Variants:")}
{button}
{bigText("Result:")}
{result}
{error}
<BigText>Operations:</BigText>
<Button onPress={this.verifyLiveness}>Verify Liveness</Button>
<Button onPress={this.enroll}>Enroll</Button>
{this.state.faceID && <Button onPress={this.authenticate}>Authenticate</Button>}
{this.state.result && (
<>
<BigText>Result:</BigText>
<ScrollView contentContainerStyle={styles.scrollContainer}>
<BigText>{prettify(this.state.result)}</BigText>
</ScrollView>
</>
)}
{this.state.error && (
<>
<BigText>Error:</BigText>
<BigText>{prettify(this.state.error)}</BigText>
</>
)}
</View>
);
};
renderResult = () => {
const { result } = this.state;
if (!result) return;

const { faceMetrics = {} } = result;
const { facemap, auditTrail = [] } = faceMetrics;
const images = auditTrail.map((uri, i) => (
<Image key={`image${i}`} style={styles.image} source={{ uri }} />
));
return (
<ScrollView contentContainerStyle={styles.scrollContainer}>
{bigText(prettify(result))}
{images}
</ScrollView>
);
};
renderError = () => {
return (
this.state.error && (
<View key="error">{bigText(prettify(this.state.error))}</View>
)
);
};
)
}
}

const styles = StyleSheet.create({
scrollContainer: {},
container: {
flex: 1,
justifyContent: "center",
alignItems: "center"
justifyContent: 'center',
alignItems: 'center',
},
button: {
padding: 10
padding: 10,
},
buttonText: {
color: "blue"
color: 'blue',
fontSize: 30,
},
bigText: {
fontSize: 20
},
hugeText: {
fontSize: 30
fontSize: 20,
},
image: {
flex: 1,
resizeMode: "contain",
resizeMode: 'contain',
minWidth: 300,
minHeight: 300
}
});
minHeight: 300,
},
})
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
See example code in `src/App.js`

1. run `yarn` or `npm install` to install dependencies
2. download and copy `ZoomAuthenticationHybrid.framework` to `ios/`
3. copy your token to `license-key.json`, e.g.:
2. [download](https://dev.facetec.com/downloads) the sdk and copy `FaceTecSDK.framework` to `ios/`
3. copy your deviceKeyIdentifier to `device-key-identifier.json`, e.g.:

```json
"abcdefg"
Expand Down
41 changes: 23 additions & 18 deletions ios/rnzoomexample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADBDB9271DFEBF0700ED6528 /* libRCTBlob.a */; };
AE9D6FC823C170FF00B12F1C /* libRNReactNativeZoomSdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AEAC1A2A229E18F300EFF2FA /* libRNReactNativeZoomSdk.a */; };
AE9D6FC923C1712500B12F1C /* ZoomAuthentication.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE9D6FBA23C1620800B12F1C /* ZoomAuthentication.framework */; };
AE9D6FCA23C1712500B12F1C /* ZoomAuthentication.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = AE9D6FBA23C1620800B12F1C /* ZoomAuthentication.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
AE29D021253DD6A900B599B8 /* FaceTecSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AE29D020253DD6A900B599B8 /* FaceTecSDK.framework */; };
AE29D022253DD89600B599B8 /* libRNReactNativeZoomSdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AEAC1A2A229E18F300EFF2FA /* libRNReactNativeZoomSdk.a */; };
AE29D024253DF15400B599B8 /* FaceTecSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = AE29D020253DD6A900B599B8 /* FaceTecSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
AEAC1A59229E1A2D00EFF2FA /* Dummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEAC1A58229E1A2D00EFF2FA /* Dummy.swift */; };
ED297163215061F000B7C4FE /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED297162215061F000B7C4FE /* JavaScriptCore.framework */; };
F13B643C617D46E983EC1176 /* libRNImageStore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8ED38DB433DB4D9AB89FE806 /* libRNImageStore.a */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -308,13 +307,23 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
AE29D023253DF14700B599B8 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
AE29D024253DF15400B599B8 /* FaceTecSDK.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
AEAC19F2229E164A00EFF2FA /* Copy Files */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
AE9D6FCA23C1712500B12F1C /* ZoomAuthentication.framework in Copy Files */,
);
name = "Copy Files";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -345,10 +354,8 @@
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
889193BC8F6143CDAACABDF6 /* libRNReactNativeZoomSdk.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNReactNativeZoomSdk.a; sourceTree = "<group>"; };
8ED38DB433DB4D9AB89FE806 /* libRNImageStore.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNImageStore.a; sourceTree = "<group>"; };
ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = "<group>"; };
AE9D6FBA23C1620800B12F1C /* ZoomAuthentication.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ZoomAuthentication.framework; sourceTree = "<group>"; };
AE29D020253DD6A900B599B8 /* FaceTecSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = FaceTecSDK.framework; sourceTree = "<group>"; };
AEAC1A57229E1A2C00EFF2FA /* rnzoomexample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "rnzoomexample-Bridging-Header.h"; sourceTree = "<group>"; };
AEAC1A58229E1A2D00EFF2FA /* Dummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dummy.swift; sourceTree = "<group>"; };
C1EE1150452D4AD99C06DD0C /* RNReactNativeZoomSdk.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNReactNativeZoomSdk.xcodeproj; path = "../node_modules/react-native-facetec-zoom/ios/RNReactNativeZoomSdk.xcodeproj"; sourceTree = "<group>"; };
Expand All @@ -363,7 +370,6 @@
files = (
ED297163215061F000B7C4FE /* JavaScriptCore.framework in Frameworks */,
ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */,
AE9D6FC823C170FF00B12F1C /* libRNReactNativeZoomSdk.a in Frameworks */,
11D1A2F320CAFA9E000508D9 /* libRCTAnimation.a in Frameworks */,
146834051AC3E58100842450 /* libReact.a in Frameworks */,
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */,
Expand All @@ -373,10 +379,10 @@
00C302E91ABCBA2D00DB3ED1 /* libRCTNetwork.a in Frameworks */,
139105C61AF99C1200B5F7CC /* libRCTSettings.a in Frameworks */,
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
AE9D6FC923C1712500B12F1C /* ZoomAuthentication.framework in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
AE29D021253DD6A900B599B8 /* FaceTecSDK.framework in Frameworks */,
AE29D022253DD89600B599B8 /* libRNReactNativeZoomSdk.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
F13B643C617D46E983EC1176 /* libRNImageStore.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -465,7 +471,7 @@
13B07FAE1A68108700A75B9A /* rnzoomexample */ = {
isa = PBXGroup;
children = (
AE9D6FBA23C1620800B12F1C /* ZoomAuthentication.framework */,
AE29D020253DD6A900B599B8 /* FaceTecSDK.framework */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.m */,
Expand Down Expand Up @@ -603,8 +609,6 @@
AEAC1A00229E18F100EFF2FA /* Recovered References */ = {
isa = PBXGroup;
children = (
889193BC8F6143CDAACABDF6 /* libRNReactNativeZoomSdk.a */,
8ED38DB433DB4D9AB89FE806 /* libRNImageStore.a */,
);
name = "Recovered References";
sourceTree = "<group>";
Expand All @@ -630,6 +634,7 @@
AEAC19F2229E164A00EFF2FA /* Copy Files */,
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
AEAC1A56229E19D300EFF2FA /* Run Script */,
AE29D023253DF14700B599B8 /* Embed Frameworks */,
);
buildRules = (
);
Expand All @@ -650,7 +655,7 @@
ORGANIZATIONNAME = Facebook;
TargetAttributes = {
13B07F861A680F5B00A75B9A = {
DevelopmentTeam = 94V7783F74;
DevelopmentTeam = 3C949BWG27;
LastSwiftMigration = 1020;
};
};
Expand Down Expand Up @@ -1088,7 +1093,7 @@
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = 94V7783F74;
DEVELOPMENT_TEAM = 3C949BWG27;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand All @@ -1110,7 +1115,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.facetec.ZoomAuthentication-Sample-App";
PRODUCT_BUNDLE_IDENTIFIER = mv.zoomsdkexample;
PRODUCT_NAME = rnzoomexample;
SWIFT_OBJC_BRIDGING_HEADER = "rnzoomexample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand Down Expand Up @@ -1147,7 +1152,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = io.tradle.zoomsdkexample;
PRODUCT_BUNDLE_IDENTIFIER = mv.zoomsdkexample;
PRODUCT_NAME = rnzoomexample;
SWIFT_OBJC_BRIDGING_HEADER = "rnzoomexample-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"react": "16.8.3",
"react-native": "0.59.9",
"react-native-facetec-zoom": "tradle/react-native-facetec-zoom#mv/sdk8.x",
"react-native-facetec-zoom": "https://github.com/tradle/react-native-facetec-zoom#mv/sdk9.x",
"react-native-image-store": "^1.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4858,9 +4858,9 @@ react-is@^16.8.1, react-is@^16.8.3, react-is@^16.8.4:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==

react-native-facetec-zoom@tradle/react-native-facetec-zoom#mv/sdk8.x:
"react-native-facetec-zoom@https://github.com/tradle/react-native-facetec-zoom#mv/sdk9.x":
version "1.2.0"
resolved "https://codeload.github.com/tradle/react-native-facetec-zoom/tar.gz/8c1a9b2028acd19a9be136f0d10f2feed02258dc"
resolved "https://github.com/tradle/react-native-facetec-zoom#a90782a3fd5536e2eac7b433df2011a67b476110"

react-native-image-store@^1.0.0:
version "1.0.0"
Expand Down

0 comments on commit d37a501

Please sign in to comment.