From 92daa40e1771053b00ce083aa936c3a7eae42508 Mon Sep 17 00:00:00 2001 From: bharti-sagar Date: Thu, 9 Feb 2023 12:57:09 +0530 Subject: [PATCH] SDK-753 update readme for sample apps for ios sdk --- Samples/README.md | 131 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 118 insertions(+), 13 deletions(-) diff --git a/Samples/README.md b/Samples/README.md index a8d81063..bd11c85c 100644 --- a/Samples/README.md +++ b/Samples/README.md @@ -1,13 +1,118 @@ -Please follow these below steps to run samples - -- Navigate to the desired sample -- In CMD, run the command, pod install -- Open the .xcworkspace file using xcode -- Click on Build and run - -`Note`: -In every sample, in Skyflow.Config(), replace with the following fields: -1. Replace the placeholder "" with the correct vaultId you want to connect -2. Replace the placeholder "" with the correct vaultURL -3. Implement the bearer token endpoint using server side auth SDK and service account file. - Replace the placeholder "" with the bearer token endpoint which gives the bearerToken, implemented at your backend. \ No newline at end of file +# iOS SDK samples +Test the SDK by adding `VAULT-ID`, `VAULT-URL`, and `SERVICE-ACCOUNT` details in the required places for each sample. + +### Prerequisites +- iOS 13.0.0 or higher +- [cocoapods](https://cocoapods.org) +- Xcode +- [Node.js](https://nodejs.org/en/) 10 or higher +- [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) 6.x.x or higher + +- [express.js](http://expressjs.com/en/starter/hello-world.html) + + +### Create the vault +1. In a browser, sign in to Skyflow Studio. +2. Create a vault by clicking **Create Vault** > **Start With a Template** > **PIIData**. +3. Once the vault is ready, click the gear icon and select **Edit Vault Details**. +4. Note your **Vault URL** and **Vault ID** values, then click Cancel. You'll need these later. + +### Create a service account +1. In the side navigation click, **IAM** > **Service Accounts** > **New Service Account**. +2. For **Name**, enter "SDK Samples". For Roles, choose **Vault Editor**. +3. Click **Create**. Your browser downloads a **credentials.json** file. Keep this file secure. You'll need it to generate bearer tokens. + +### Create a bearer token generation endpoint +1. Create a new directory named `bearer-token-generator`. + + mkdir bearer-token-generator +2. Navigate to `bearer-token-generator` directory. + + cd bearer-token-generator +3. Initialize npm + + npm init +4. Install `skyflow-node` + + npm i skyflow-node +5. Move the downloaded “credentials.json” file into the bearer-token-generator directory. +6. Create `index.js` file +7. Open `index.js` file +8. populate `index.js` file with below code snippet +```javascript +const express = require("express"); +const app = express(); +const cors = require("cors"); +const port = 3000; +const { + generateBearerToken, + isExpired +} = require("skyflow-node"); + +app.use(cors()); + +let filepath = "credentials.json"; +let bearerToken = ""; + +const getSkyflowBearerToken = () => { + return new Promise(async (resolve, reject) => { + try { + if (!isExpired(bearerToken)) { + resolve(bearerToken); + } + else { + let response = await generateBearerToken(filepath); + bearerToken = response.accessToken; + resolve(bearerToken); + } + } catch (e) { + reject(e); + } + }); +} +app.get("/", async (req, res) => { + let bearerToken = await getSkyflowBearerToken(); + res.json({"accessToken" : bearerToken}); +}); + +app.listen(port, () => { + console.log(`Server is listening on port ${port}`); +}) +``` +9. Start the server + + node index.js + server will start at `localhost:3000` +10. Your **** with `http://localhost:3000/` + +## The samples +### Collect and reveal +This sample demonstrates how to use Skyflow Elements to collect sensitive user information and reveal it to a user. +#### Configure +1. In `Skyflow.Configuration()` of [ViewController.swift](CollectAndRevealSample/CollectAndRevealSample/ViewController.swift), replace with the following fields: + - The placeholder "" with the vault ID you noted previously. + - The placeholder "" with the vault URL you noted previously. +2. Replace the placeholder "" 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. + +#### Running the sample + 1. Open terminal + 2. Navigate to CollectAndRevealSample + 3. Run + pod install + 4. Open the CollectAndRevealSample.xcworkspace file using xcode. + 5. Build and run using command + R. + +### Custom validation +This sample demonstrates how to apply custom validation rules to Skyflow elements to restrict the type of input a user can provide. +#### Configure +In `Skyflow.Configuration()` of [ViewController.swift](Validations/Validations/ViewController.swift), replace with the following fields: +1. Replace the placeholder "" in the configuration with the vault ID previously noted. Replace the placeholder "" with the vault URL previously noted. +2. Replace the placeholder "" 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. + +#### Running the sample + 1. Open terminal + 2. Navigate to Validations + 3. Run + pod install + 4. Open the Validations.xcworkspace file using xcode + 5. Build and run using command + R.