|
1 | | -Please follow these below steps to run samples |
2 | | - |
3 | | -- Navigate to the desired sample |
4 | | -- In CMD, run the command, pod install |
5 | | -- Open the .xcworkspace file using xcode |
6 | | -- Click on Build and run |
7 | | - |
8 | | -`Note`: |
9 | | -In every sample, in Skyflow.Config(), replace with the following fields: |
10 | | -1. Replace the placeholder "<VAULT_ID>" with the correct vaultId you want to connect |
11 | | -2. Replace the placeholder "<VAULT_URL>" with the correct vaultURL |
12 | | -3. Implement the bearer token endpoint using server side auth SDK and service account file. |
13 | | - Replace the placeholder "<TOKEN_END_POINT_URL>" with the bearer token endpoint which gives the bearerToken, implemented at your backend. |
| 1 | +# iOS SDK samples |
| 2 | +Test the SDK by adding `VAULT-ID`, `VAULT-URL`, and `SERVICE-ACCOUNT` details in the required places for each sample. |
| 3 | + |
| 4 | +### Prerequisites |
| 5 | +- iOS 13.0.0 or higher |
| 6 | +- [cocoapods](https://cocoapods.org) |
| 7 | +- Xcode |
| 8 | +- [Node.js](https://nodejs.org/en/) 10 or higher |
| 9 | +- [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) 6.x.x or higher |
| 10 | + |
| 11 | +- [express.js](http://expressjs.com/en/starter/hello-world.html) |
| 12 | + |
| 13 | + |
| 14 | +### Create the vault |
| 15 | +1. In a browser, sign in to Skyflow Studio. |
| 16 | +2. Create a vault by clicking **Create Vault** > **Start With a Template** > **PIIData**. |
| 17 | +3. Once the vault is ready, click the gear icon and select **Edit Vault Details**. |
| 18 | +4. Note your **Vault URL** and **Vault ID** values, then click Cancel. You'll need these later. |
| 19 | + |
| 20 | +### Create a service account |
| 21 | +1. In the side navigation click, **IAM** > **Service Accounts** > **New Service Account**. |
| 22 | +2. For **Name**, enter "SDK Samples". For Roles, choose **Vault Editor**. |
| 23 | +3. Click **Create**. Your browser downloads a **credentials.json** file. Keep this file secure. You'll need it to generate bearer tokens. |
| 24 | + |
| 25 | +### Create a bearer token generation endpoint |
| 26 | +1. Create a new directory named `bearer-token-generator`. |
| 27 | + |
| 28 | + mkdir bearer-token-generator |
| 29 | +2. Navigate to `bearer-token-generator` directory. |
| 30 | + |
| 31 | + cd bearer-token-generator |
| 32 | +3. Initialize npm |
| 33 | + |
| 34 | + npm init |
| 35 | +4. Install `skyflow-node` |
| 36 | + |
| 37 | + npm i skyflow-node |
| 38 | +5. Move the downloaded “credentials.json” file #Create a service account account into the bearer-token-generator directory. |
| 39 | +6. Create `index.js` file |
| 40 | +7. Open `index.js` file |
| 41 | +8. populate `index.js` file with below code snippet |
| 42 | +```javascript |
| 43 | +const express = require("express"); |
| 44 | +const app = express(); |
| 45 | +const cors = require("cors"); |
| 46 | +const port = 3000; |
| 47 | +const { |
| 48 | + generateBearerToken, |
| 49 | + isExpired |
| 50 | +} = require("skyflow-node"); |
| 51 | + |
| 52 | +app.use(cors()); |
| 53 | + |
| 54 | +let filepath = "credentials.json"; |
| 55 | +let bearerToken = ""; |
| 56 | + |
| 57 | +const getSkyflowBearerToken = () => { |
| 58 | + return new Promise(async (resolve, reject) => { |
| 59 | + try { |
| 60 | + if (!isExpired(bearerToken)) { |
| 61 | + resolve(bearerToken); |
| 62 | + } |
| 63 | + else { |
| 64 | + let response = await generateBearerToken(filepath); |
| 65 | + bearerToken = response.accessToken; |
| 66 | + resolve(bearerToken); |
| 67 | + } |
| 68 | + } catch (e) { |
| 69 | + reject(e); |
| 70 | + } |
| 71 | + }); |
| 72 | +} |
| 73 | +app.get("/", async (req, res) => { |
| 74 | + let bearerToken = await getSkyflowBearerToken(); |
| 75 | + res.json({"accessToken" : bearerToken}); |
| 76 | +}); |
| 77 | + |
| 78 | +app.listen(port, () => { |
| 79 | + console.log(`Server is listening on port ${port}`); |
| 80 | +}) |
| 81 | +``` |
| 82 | +9. Start the server |
| 83 | + |
| 84 | + node index.js |
| 85 | + server will start at `localhost:3000` |
| 86 | +10. Your **<TOKEN_END_POINT_URL>** with `http://localhost:3000/` |
| 87 | + |
| 88 | +## The samples |
| 89 | +### Collect and reveal |
| 90 | +This sample demonstrates how to use Skyflow Elements to collect sensitive user information and reveal it to a user. |
| 91 | +#### Configure |
| 92 | +1. In `Skyflow.Configuration()` of [ViewController.swift](CollectAndRevealSample/CollectAndRevealSample/ViewController.swift), replace with the following fields: |
| 93 | + - The placeholder "<VAULT_ID>" with the vault ID you noted previously. |
| 94 | + - The placeholder "<VAULT_URL>" with the vault URL you noted previously. |
| 95 | +2. Replace the placeholder "<TOKEN_END_POINT_URL>" in [ExampleTokenProvider.swift](https://github.com/skyflowapi/skyflow-iOS/blob/SDK-753-update-sample-app-readme/Samples/CollectAndRevealSample/CollectAndRevealSample/ExampleTokenProvider.swift) with the service account bearer token endpoint. |
| 96 | + |
| 97 | +#### Running the sample |
| 98 | + 1. Open terminal |
| 99 | + 2. Navigate to CollectAndRevealSample |
| 100 | + 3. Run |
| 101 | + pod install |
| 102 | + 4. Open the CollectAndRevealSample.xcworkspace file using xcode. |
| 103 | + 5. Build and run using command + R. |
| 104 | + |
| 105 | +### Custom validation |
| 106 | +This sample demonstrates how to apply custom validation rules to Skyflow elements to restrict the type of input a user can provide. |
| 107 | +#### Configure |
| 108 | +In `Skyflow.Configuration()` of [ViewController.swift](Validations/Validations/ViewController.swift), replace with the following fields: |
| 109 | +1. Replace the placeholder "<VAULT_ID>" in the configuration with the vault ID previously noted. Replace the placeholder "<VAULT_URL>" with the vault URL previously noted. |
| 110 | +2. Replace the placeholder "<TOKEN_END_POINT_URL>" in [ExampleTokenProvider.swift](https://github.com/skyflowapi/skyflow-iOS/blob/SDK-753-update-sample-app-readme/Samples/Validations/Validations/ExampleTokenProvider.swift) with the service account bearer token endpoint. |
| 111 | + |
| 112 | +#### Running the sample |
| 113 | + 1. Open terminal |
| 114 | + 2. Navigate to Validations |
| 115 | + 3. Run |
| 116 | + pod install |
| 117 | + 4. Open the Validations.xcworkspace file using xcode |
| 118 | + 5. Build and run using command + R. |
0 commit comments