From c4d022f8a091f5c5f55ecf29172a00505a92ece5 Mon Sep 17 00:00:00 2001 From: puneet Date: Mon, 17 Oct 2022 19:20:57 +0530 Subject: [PATCH 1/4] [SDK-753] Update sample readme --- Samples/README.md | 149 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 136 insertions(+), 13 deletions(-) diff --git a/Samples/README.md b/Samples/README.md index a8d81063..bd9e26ce 100644 --- a/Samples/README.md +++ b/Samples/README.md @@ -1,13 +1,136 @@ -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 +# skyflow-ios sdk sample templates +Use this folder to test the functionalities of iOS-SDK just by adding `VAULT-ID` `VAULT-URL` and `SERVICE-ACCOUNT` details at the required place. + +### Prerequisites +- iOS 13.0.0 and above +- cocoapods +- Xcode +- [Node.js](https://nodejs.org/en/) version 10 or above +- [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) version 6.x.x + +- [express.js](http://expressjs.com/en/starter/hello-world.html) +## Configure +- Before you can run the sample app, create a vault. +- `TOKEN_END_POINT_URL` for generating bearer token. + + +### Create the vault +1. In a browser, navigate to Skyflow Studio and log in. +2. Create a vault by clicking **Create Vault** > **Start With a Template** > **PIIData**. +3. Once the vault is created, 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 **Test-Js-Sdk-Sample**. For Roles, choose the required roles for specific action. +3. Click **Create**. Your browser downloads a **credentials.json** file. Keep this file secure, as you'll need it in the next steps. + +### Create TOKEN_END_POINT_URL +- Create a new directory named `bearer-token-generator`. + + mkdir bearer-token-generator +- Navigate to `bearer-token-generator` directory. + + cd bearer-token-generator +- Initialize npm + + npm init +- Install `skyflow-node` + + npm i skyflow-node +- Create `index.js` file +- Open `index.js` file +- populate `index.js` file with below code snippet +```javascript +const express = require('express') +const app = express() +var cors = require('cors') +const port = 3000 +const { + generateBearerToken, + isExpired +} = require('skyflow-node'); + +app.use(cors()) + +let filepath = 'cred.json'; +let bearerToken = ""; + +function 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}`) +}) + +``` +- Start the server + + node index.js + server will start at `localhost:3000` +- Your **** with `http://localhost:3000/` + +Running sample templates +- [`CollectAndRevealSample`](CollectAndRevealSample) + - This sample illustrates how to use secure Skyflow elements to collect sensitive user information and reveal it to the user via tokens. + - Configure + - In `Skyflow.Configuration()` of [ViewController.swift](CollectAndRevealSample/CollectAndRevealSample/ViewController.swift), replace with the following fields: + - Replace the placeholder "" with the correct vaultId you want to connect + - Replace the placeholder "" with the correct vaultURL + - Update `Fields` struct in [ResponseStructs.swift](CollectAndRevealSample/CollectAndRevealSample/ResponseStructs.swift) with field name of used vault. + - For ex: + ```swift + + struct Fields: Codable { + let name: NameField + let cvv: String + let cardExpiration: String + let cardNumber: String + let skyflow_id: String + } + + ``` + The fields can be different depending upon the vault. + - Update + - Replace the placeholder "" of [ExampleTokenProvider.swift](CollectAndRevealSample/CollectAndRevealSample/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. + - Running the sample + - Open CMD + - Navigate to `CollectAndRevealSample` + - Run + + pod install + - Open the [`CollectAndRevealSample.xcworkspace](`CollectAndRevealSample/`CollectAndRevealSample.xcworkspace) file using xcode + - click on build and run + +- [`Validations`](Validations) + - This sample illustrates how to apply custom validation rules on secure Skyflow Collect 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: + - Replace the placeholder "" in the configuration with the correct vaultId you want to connect + - Replace the placeholder "" with the correct vaultURL + - Replace the placeholder "" in [ExampleTokenProvider.swift](Validations/Validations/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. + - Running the sample + - Open CMD + - Navigate to `Validations` + - Run + + pod install + - Open the [Validations.xcworkspace](Validations/Validations.xcworkspace) file using xcode + - click on build and run From afb5eace1e551654d788631fe3f71b1691c1a229 Mon Sep 17 00:00:00 2001 From: puneet Date: Tue, 25 Oct 2022 13:22:26 +0530 Subject: [PATCH 2/4] [SDK-753] Update sample readme Signed-off-by: puneet --- Samples/README.md | 117 ++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 61 deletions(-) diff --git a/Samples/README.md b/Samples/README.md index bd9e26ce..b794e3c2 100644 --- a/Samples/README.md +++ b/Samples/README.md @@ -1,46 +1,43 @@ -# skyflow-ios sdk sample templates -Use this folder to test the functionalities of iOS-SDK just by adding `VAULT-ID` `VAULT-URL` and `SERVICE-ACCOUNT` details at the required place. +# 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 and above -- cocoapods +- iOS 13.0.0 or higher +- [cocoapods](https://cocoapods.org) - Xcode -- [Node.js](https://nodejs.org/en/) version 10 or above -- [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) version 6.x.x +- [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) -## Configure -- Before you can run the sample app, create a vault. -- `TOKEN_END_POINT_URL` for generating bearer token. ### Create the vault -1. In a browser, navigate to Skyflow Studio and log in. +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 created, 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. +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 **Test-Js-Sdk-Sample**. For Roles, choose the required roles for specific action. -3. Click **Create**. Your browser downloads a **credentials.json** file. Keep this file secure, as you'll need it in the next steps. +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 TOKEN_END_POINT_URL -- Create a new directory named `bearer-token-generator`. +### Create a bearer token generation endpoint +1. Create a new directory named `bearer-token-generator`. mkdir bearer-token-generator -- Navigate to `bearer-token-generator` directory. +2. Navigate to `bearer-token-generator` directory. cd bearer-token-generator -- Initialize npm +3. Initialize npm npm init -- Install `skyflow-node` +4. Install `skyflow-node` npm i skyflow-node -- Create `index.js` file -- Open `index.js` file -- populate `index.js` file with below code snippet +5. Create `index.js` file +6. Open `index.js` file +7. populate `index.js` file with below code snippet ```javascript const express = require('express') const app = express() @@ -79,25 +76,23 @@ app.get('/', async (req, res) => { app.listen(port, () => { console.log(`Server is listening on port ${port}`) }) - ``` -- Start the server +8. Start the server node index.js server will start at `localhost:3000` -- Your **** with `http://localhost:3000/` +9. Your **** with `http://localhost:3000/` -Running sample templates -- [`CollectAndRevealSample`](CollectAndRevealSample) - - This sample illustrates how to use secure Skyflow elements to collect sensitive user information and reveal it to the user via tokens. - - Configure - - In `Skyflow.Configuration()` of [ViewController.swift](CollectAndRevealSample/CollectAndRevealSample/ViewController.swift), replace with the following fields: +## The samples +### Collect and reveal +This sample illustrates how to use secure Skyflow elements to collect sensitive user information and reveal it to the user via tokens. +#### Configure +1. In `Skyflow.Configuration()` of [ViewController.swift](CollectAndRevealSample/CollectAndRevealSample/ViewController.swift), replace with the following fields: - Replace the placeholder "" with the correct vaultId you want to connect - Replace the placeholder "" with the correct vaultURL - - Update `Fields` struct in [ResponseStructs.swift](CollectAndRevealSample/CollectAndRevealSample/ResponseStructs.swift) with field name of used vault. - - For ex: - ```swift - +2. Update `Fields` struct in [ResponseStructs.swift](CollectAndRevealSample/CollectAndRevealSample/ResponseStructs.swift) with field name of used vault. For ex: + + ```swift struct Fields: Codable { let name: NameField let cvv: String @@ -105,32 +100,32 @@ Running sample templates let cardNumber: String let skyflow_id: String } - - ``` - The fields can be different depending upon the vault. - - Update - - Replace the placeholder "" of [ExampleTokenProvider.swift](CollectAndRevealSample/CollectAndRevealSample/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. - - Running the sample - - Open CMD - - Navigate to `CollectAndRevealSample` - - Run + ``` + + The fields can be different depending upon the vault. +3. Update +4. Replace the placeholder "" of [ExampleTokenProvider.swift](CollectAndRevealSample/CollectAndRevealSample/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. + 5. Running the sample + 1. Open CMD + 2. Navigate to `CollectAndRevealSample` + 3. Run pod install - - Open the [`CollectAndRevealSample.xcworkspace](`CollectAndRevealSample/`CollectAndRevealSample.xcworkspace) file using xcode - - click on build and run - -- [`Validations`](Validations) - - This sample illustrates how to apply custom validation rules on secure Skyflow Collect 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: - - Replace the placeholder "" in the configuration with the correct vaultId you want to connect - - Replace the placeholder "" with the correct vaultURL - - Replace the placeholder "" in [ExampleTokenProvider.swift](Validations/Validations/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. - - Running the sample - - Open CMD - - Navigate to `Validations` - - Run - - pod install - - Open the [Validations.xcworkspace](Validations/Validations.xcworkspace) file using xcode - - click on build and run + 4. Open the [`CollectAndRevealSample.xcworkspace](`CollectAndRevealSample/`CollectAndRevealSample.xcworkspace) file using xcode + 5. click on build and run + +### Validations +This sample illustrates how to apply custom validation rules on secure Skyflow Collect elements to restrict the type of input a user can provide. +#### Configure +1. In `Skyflow.Configuration()` of [ViewController.swift](Validations/Validations/ViewController.swift), replace with the following fields: +2. Replace the placeholder "" in the configuration with the correct vaultId you want to connect +3. Replace the placeholder "" with the correct vaultURL +4. Replace the placeholder "" in [ExampleTokenProvider.swift](Validations/Validations/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. +5. Running the sample + 1. Open CMD + 2. Navigate to `Validations` + 3. Run + + pod install + 4. Open the [Validations.xcworkspace](Validations/Validations.xcworkspace) file using xcode + 5. click on build and run From 54f51168a8e108e94c0dba5d98836b8c9f11bb0a Mon Sep 17 00:00:00 2001 From: puneet Date: Wed, 2 Nov 2022 10:46:36 +0530 Subject: [PATCH 3/4] [SDK-753] Finxed typo in sample readme --- Samples/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Samples/README.md b/Samples/README.md index b794e3c2..e8150807 100644 --- a/Samples/README.md +++ b/Samples/README.md @@ -105,13 +105,14 @@ This sample illustrates how to use secure Skyflow elements to collect sensitive The fields can be different depending upon the vault. 3. Update 4. Replace the placeholder "" of [ExampleTokenProvider.swift](CollectAndRevealSample/CollectAndRevealSample/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. - 5. Running the sample + +#### Running the sample 1. Open CMD 2. Navigate to `CollectAndRevealSample` 3. Run pod install - 4. Open the [`CollectAndRevealSample.xcworkspace](`CollectAndRevealSample/`CollectAndRevealSample.xcworkspace) file using xcode + 4. Open the `CollectAndRevealSample.xcworkspace` file using xcode 5. click on build and run ### Validations @@ -121,11 +122,11 @@ This sample illustrates how to apply custom validation rules on secure Skyflow C 2. Replace the placeholder "" in the configuration with the correct vaultId you want to connect 3. Replace the placeholder "" with the correct vaultURL 4. Replace the placeholder "" in [ExampleTokenProvider.swift](Validations/Validations/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. -5. Running the sample +#### Running the sample 1. Open CMD 2. Navigate to `Validations` 3. Run pod install - 4. Open the [Validations.xcworkspace](Validations/Validations.xcworkspace) file using xcode + 4. Open the `Validations.xcworkspace` file using xcode 5. click on build and run From 90e26cf1f3a038794e9bcce495676e4d8e4e9875 Mon Sep 17 00:00:00 2001 From: puneet Date: Wed, 2 Nov 2022 12:11:18 +0530 Subject: [PATCH 4/4] [SDK-753] Fixed typo in sample readme --- Samples/README.md | 116 +++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 64 deletions(-) diff --git a/Samples/README.md b/Samples/README.md index e8150807..f0fe98dd 100644 --- a/Samples/README.md +++ b/Samples/README.md @@ -35,98 +35,86 @@ Test the SDK by adding `VAULT-ID`, `VAULT-URL`, and `SERVICE-ACCOUNT` details in 4. Install `skyflow-node` npm i skyflow-node -5. Create `index.js` file -6. Open `index.js` file -7. populate `index.js` file with below code snippet +5. Move the downloaded “credentials.json” file #Create a service account account 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() -var cors = require('cors') -const port = 3000 +const express = require("express"); +const app = express(); +const cors = require("cors"); +const port = 3000; const { - generateBearerToken, - isExpired -} = require('skyflow-node'); + generateBearerToken, + isExpired +} = require("skyflow-node"); -app.use(cors()) +app.use(cors()); -let filepath = 'cred.json'; +let filepath = "credentials.json"; let bearerToken = ""; -function 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); - } - }); +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.get("/", async (req, res) => { + let bearerToken = await getSkyflowBearerToken(); + res.json({"accessToken" : bearerToken}); +}); app.listen(port, () => { - console.log(`Server is listening on port ${port}`) + console.log(`Server is listening on port ${port}`); }) ``` -8. Start the server +9. Start the server node index.js server will start at `localhost:3000` -9. Your **** with `http://localhost:3000/` +10. Your **** with `http://localhost:3000/` ## The samples ### Collect and reveal -This sample illustrates how to use secure Skyflow elements to collect sensitive user information and reveal it to the user via tokens. +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: - - Replace the placeholder "" with the correct vaultId you want to connect - - Replace the placeholder "" with the correct vaultURL -2. Update `Fields` struct in [ResponseStructs.swift](CollectAndRevealSample/CollectAndRevealSample/ResponseStructs.swift) with field name of used vault. For ex: - - ```swift - struct Fields: Codable { - let name: NameField - let cvv: String - let cardExpiration: String - let cardNumber: String - let skyflow_id: String - } - ``` - - The fields can be different depending upon the vault. -3. Update -4. Replace the placeholder "" of [ExampleTokenProvider.swift](CollectAndRevealSample/CollectAndRevealSample/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. + - 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 CMD - 2. Navigate to `CollectAndRevealSample` + 2. Navigate to CollectAndRevealSample 3. Run pod install - 4. Open the `CollectAndRevealSample.xcworkspace` file using xcode - 5. click on build and run - -### Validations -This sample illustrates how to apply custom validation rules on secure Skyflow Collect elements to restrict the type of input a user can provide. + 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 -1. In `Skyflow.Configuration()` of [ViewController.swift](Validations/Validations/ViewController.swift), replace with the following fields: -2. Replace the placeholder "" in the configuration with the correct vaultId you want to connect -3. Replace the placeholder "" with the correct vaultURL -4. Replace the placeholder "" in [ExampleTokenProvider.swift](Validations/Validations/ExampleTokenProvider.swift) with the bearer token endpoint which gives the bearerToken, implemented at your backend or `http://localhost:3000/`. +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 CMD - 2. Navigate to `Validations` + 2. Navigate to Validations 3. Run pod install - 4. Open the `Validations.xcworkspace` file using xcode - 5. click on build and run + 4. Open the Validations.xcworkspace file using xcode + 5. Build and run using command + R.