How to protect Google Maps API key on Ionic app?

前端 未结 2 1626
盖世英雄少女心
盖世英雄少女心 2021-01-17 15:24

I have Ionic PWA app published for Android and iOS (I used Capacitor to generate the native build). In the frontend code, it has my Google Maps API key, however, I can\'t re

2条回答
  •  半阙折子戏
    2021-01-17 15:58

    You can configure the hostname of capacitor apps

    "server": {
        // You can configure the local hostname, but it's recommended to keep localhost
        // as it allows to run web APIs that require a secure context such as
        // navigator.geolocation and MediaDevices.getUserMedia.
        "hostname": "unique-app",
      }
    

    and then restrict the the API keys to capacitor://unique-app

    https://capacitor.ionicframework.com/docs/basics/configuring-your-app

提交回复
热议问题