-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from animo/card-integration
feat: auth flow
- Loading branch information
Showing
8 changed files
with
490 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
import { addMessageListener, initializeSdk, sendCommand } from '@animo-id/expo-ausweis-sdk' | ||
import { useEffect, useState } from 'react' | ||
import { AusweisAuthFlow } from '@animo-id/expo-ausweis-sdk' | ||
import { useState } from 'react' | ||
import { Button } from 'react-native' | ||
import { StyleSheet, Text, View } from 'react-native' | ||
|
||
export default function App() { | ||
const [isSdkInitialized, setIsSdkInitialized] = useState(false) | ||
const [message, setMessage] = useState<string>() | ||
const [flow, setFlow] = useState<AusweisAuthFlow>() | ||
|
||
// Setup listener | ||
useEffect( | ||
addMessageListener((message) => { | ||
console.log('received message', JSON.stringify(message, null, 2)) | ||
}).remove, | ||
[] | ||
) | ||
const cancelFlow = () => | ||
flow | ||
?.cancel() | ||
.then(() => setFlow(undefined)) | ||
.catch((error) => setMessage(`Error canceling flow. ${error.message}`)) | ||
|
||
// Initialize SDK | ||
useEffect(() => { | ||
initializeSdk() | ||
.then(() => setIsSdkInitialized(true)) | ||
.catch((e) => { | ||
setIsSdkInitialized(true) | ||
console.log('error setting up', e) | ||
const runAuthFlow = async () => { | ||
setMessage(undefined) | ||
setFlow( | ||
new AusweisAuthFlow({ | ||
onEnterPin: ({ attemptsRemaining }) => { | ||
// Mock incorrect pin entry | ||
return attemptsRemaining === 1 ? '123456' : '123123' | ||
}, | ||
onError: ({ message, reason }) => { | ||
setFlow(undefined) | ||
setMessage(`${reason}: ${message}`) | ||
}, | ||
onSuccess: () => { | ||
setFlow(undefined) | ||
setMessage('Successfully ran auth flow') | ||
}, | ||
onInsertCard: () => { | ||
// For iOS this will show the NFC scanner modal. on Android we need | ||
// use this callback to show the NFC scanner modal. | ||
console.log('please insert card') | ||
}, | ||
}).start({ | ||
tcTokenUrl: 'https://test.governikus-eid.de/AusweisAuskunft/WebServiceRequesterServlet', | ||
}) | ||
}, []) | ||
|
||
// Send command once SDK is initialized | ||
useEffect(() => { | ||
if (!isSdkInitialized) return | ||
|
||
sendCommand({ cmd: 'GET_INFO' }) | ||
}, [isSdkInitialized]) | ||
) | ||
} | ||
|
||
return ( | ||
<View style={[StyleSheet.absoluteFill, { flex: 1, alignContent: 'center', justifyContent: 'center' }]}> | ||
<Text>Hello</Text> | ||
<Button onPress={flow ? cancelFlow : runAuthFlow} title={flow ? 'Cancel' : 'Start Auth Flow'} /> | ||
{message && <Text>{message}</Text>} | ||
</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.