Giter Site home page Giter Site logo

capacitor-community / device-check Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 121 KB

A Capacitor plugin to use Apple's DeviceCheck API

Ruby 14.18% Java 30.02% Objective-C 10.18% Swift 27.25% JavaScript 7.08% TypeScript 11.29%
capacitor devicecheck plugin

device-check's Introduction


DEVICE CHECK

@capacitor-community/device-check


The DeviceCheck API is used to reduce fraudulent use of your services by managing device state and asserting app integrity.

This plugin calls the DeviceCheck API generateToken method which returns a token that your App's server must verify with Apple Servers.

The call generateToken will return a token on success which you must send to your backend for verification. See Apple's Docs on this.

token is a base64 encoded string containing the token returned by []DCDevice.current.generateToken](https://developer.apple.com/documentation/devicecheck/dcdevice/generatetoken(completionhandler:)).

Install

npm install @capacitor-community/device-check
npx cap sync

Usage

import { DeviceCheck } from '@capacitor-community/device-check';
...
try {
      const result = await DeviceCheck.generateToken();
      console.log(`DeviceCheck token`, result.token);
    } catch (err) {
        // Recommendation: Report to backend and exit the application
    }

Versions

  • If you are using Capacitor 5 use version 5.x
  • If you are using Capacitor 6 use version 6.x

API

generateToken()

generateToken() => Promise<{ token: string; }>

Returns: Promise<{ token: string; }>


Errors

The following errors can occur and should be handled.

On Web and Android the result of generateToken will be an empty token "".

On iOS these errors can be caught in a catch:

  • DeviceCheck is not supported on this device - iOS reports that the device doesnt support the Device Check API (eg iOS less than v11)
  • DeviceCheck token encoding failed - iOS failed to encode the token.
  • DeviceCheck error: [some-error] - iOS reported some other error with the localized error description of [some-error]

device-check's People

Contributors

dtarnawsky avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.