|
| 1 | +Usage in Cordova apps |
| 2 | +===================== |
| 3 | + |
| 4 | +`Apache Cordova <https://cordova.apache.org>`_ is a mobile development |
| 5 | +framework. It allows you to use standard web technologies - HTML5, CSS3, |
| 6 | +and JavaScript for cross-platform development. Applications execute |
| 7 | +within wrappers targeted to each platform, and rely on |
| 8 | +standards-compliant API bindings to access each device's capabilities |
| 9 | +such as sensors, data, network status, etc. [#f1]_ |
| 10 | + |
| 11 | +To use remoteStorage.js in a Cordova app, you need to have the `InAppBrowser plugin |
| 12 | +<https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/>`_ |
| 13 | +installed. |
| 14 | + |
| 15 | +Cordova apps are packaged for the different platforms and installed on |
| 16 | +the device. The app doesn't need to be hosted as a web app (although it |
| 17 | +can be as well). But for the remoteStorage connection to work, you need |
| 18 | +to provide a page that is accessible via a public URL. This will be used |
| 19 | +as the redirect URL during the OAuth flow. |
| 20 | + |
| 21 | +When a user connects their storage, the OAuth dialog will open in an |
| 22 | +in-app browser window, set to show the address to prevent phishing attacks. |
| 23 | + |
| 24 | +.. image:: ../_images/cordova_oauth.png |
| 25 | + :width: 188px |
| 26 | + :align: right |
| 27 | + :alt: Screenshot of the OAuth dialog |
| 28 | + |
| 29 | +After the user authorizes the app, the server will redirect to the |
| 30 | +configured redirect URL with the authorization token added as a |
| 31 | +parameter. remoteStorage.js will intercept this redirect, extract the |
| 32 | +token from the URL and close the window. |
| 33 | + |
| 34 | +So the user doesn't actually see the page of the redirect URL and it |
| 35 | +does't need to have the remoteStorage.js library included or have any |
| 36 | +special logic at all. But you should still make sure that it can be |
| 37 | +identified as belonging to your app. Storage providers will usually |
| 38 | +show the URL in the OAuth dialog, and they may also link to it (e.g. |
| 39 | +from the list of connected apps). |
| 40 | + |
| 41 | +You can configure the redirect URL for your app, either by calling |
| 42 | + |
| 43 | +.. code:: javascript |
| 44 | +
|
| 45 | + remoteStorage.setCordovaRedirectUri('https://myapp.example.com'); |
| 46 | +
|
| 47 | +or as config when creating your rs instance: |
| 48 | + |
| 49 | +.. code:: javascript |
| 50 | +
|
| 51 | + const remoteStorage = new RemoteStorage({ |
| 52 | + cordovaRedirectUri: 'https://myapp.example.com' |
| 53 | + }); |
| 54 | +
|
| 55 | +No further action is needed and you can now use remoteStorage.js as with |
| 56 | +any other web app. |
| 57 | + |
| 58 | +Google Drive config |
| 59 | +------------------- |
| 60 | + |
| 61 | +If you wish to use the optional Google Drive adapter, you need to configure a |
| 62 | +different user agent for your app. Otherwise the authorization page will show |
| 63 | +an error to the user. |
| 64 | + |
| 65 | +In case you haven't set your own UA string already, here's how you can do it: |
| 66 | + |
| 67 | +.. code:: xml |
| 68 | +
|
| 69 | + <preference name="OverrideUserAgent" value="Mozilla/5.0 remoteStorage" /> |
| 70 | +
|
| 71 | +.. rubric:: Footnotes |
| 72 | + |
| 73 | +.. [#f1] Taken from https://cordova.apache.org/docs/en/latest/guide/overview/index.html |
0 commit comments