Skip to content

animo/expo-ausweis-sdk

Repository files navigation

Animo Logo

Expo - Ausweis SDK

Powered by   Animo Logo


License

Getting started  |  Contributing  |  License


An Expo Module and Expo Config Plugin to automatically set up and configure the Ausweis App SDK for iOS & Android in Expo apps.

Getting Started

Install the plugin and expo-build-properties using the following command. We need expo-build-properties to set the minSdkVersion for Android to at least 26, and enable useLegacyPackaging (see App Bundle in Ausweis SDK documentation).

# yarn
yarn add @animo-id/expo-ausweis-sdk expo-build-properties

# npm
npm install @animo-id/expo-ausweis-sdk expo-build-properties

# npm
pnpm install @animo-id/expo-ausweis-sdk expo-build-properties

Then add the plugin to your Expo app config (app.json, app.config.json or app.config.js) plugins array:

{
  "expo": {
    "plugins": [
      "@animo-id/expo-ausweis-sdk",
      [
        "expo-build-properties",
        {
          "android": {
            "minSdkVersion": 26,
            "useLegacyPackaging": true
          }
        }
      ]
    ]
  }
}

NOTE: the expo top level key is only needed in app.json. In app.config.json, app.config.js and app.config.ts the top level expo key is not present anymore.

And lastly, prebuild the application so the Ausweis SDK and Expo Module wrapper can be added as native dependency (If you aren't making any manual modification to the iOS and Android directories you can add them to the gitignore of your project and generate them on demand):

# yarn
yarn expo prebuild

# npm
npx expo prebuild

That's it, you now have Ausweis App SDK configured for your iOS and Android project.

Usage

You can now import @animo-id/expo-ausweis-sdk in your application and use the methods from the SDK.

You can see the available commands and messages, which are typed in the sendCommand and addMessageListener methods.

import { useEffect, useState } from 'react'
import { initializeSdk, sendCommand, addMessageListener } from '@animo-id/expo-ausweis-sdk'


export function App() {
  const [isSdkInitialized, setIsSdkInitialized] = useState(false)

  // Setup listener
  useEffect(
    addMessageListener((message) => {
      console.log('received message', JSON.stringify(message, null, 2))
    }).remove,
    []
  )

  // Initialize SDK
  useEffect(() => {
    initializeSdk()
      .then(() => setIsSdkInitialized(true))
      .catch((e) => {
        console.log('error setting up', e)
      })
  }, [])

  // Send command once SDK is initialized
  useEffect(() => {
    if (!isSdkInitialized) return

    sendCommand({ cmd: 'GET_INFO' })
  }, [isSdkInitialized])

  return null
}

Contributing

Is there something you'd like to fix or add? Great, we love community contributions! To get involved, please follow our contribution guidelines.

License

Expo Ausweis SDK is licensed under the EUPL Version 1.2. The AusweisApp SDK used by this Expo Module is also licensed under EUPL Version 1.2