-
Notifications
You must be signed in to change notification settings - Fork 2
[SDK-753] Update sample readme #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skyflow-puneet
wants to merge
4
commits into
main
Choose a base branch
from
SDK-753-update-sample-app-readme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,120 @@ | ||
| 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 "<VAULT_ID>" with the correct vaultId you want to connect | ||
| 2. Replace the placeholder "<VAULT_URL>" with the correct vaultURL | ||
| 3. Implement the bearer token endpoint using server side auth SDK and service account file. | ||
| Replace the placeholder "<TOKEN_END_POINT_URL>" with the bearer token endpoint which gives the bearerToken, implemented at your backend. | ||
| # 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 #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(); | ||
| 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` | ||
skyflow-puneet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 10. Your **<TOKEN_END_POINT_URL>** 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 "<VAULT_ID>" with the vault ID you noted previously. | ||
| - The placeholder "<VAULT_URL>" with the vault URL you noted previously. | ||
| 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. | ||
|
|
||
| #### Running the sample | ||
| 1. Open CMD | ||
| 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 "<VAULT_ID>" in the configuration with the vault ID previously noted. Replace the placeholder "<VAULT_URL>" with the vault URL previously noted. | ||
| 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. | ||
|
|
||
| #### Running the sample | ||
| 1. Open CMD | ||
| 2. Navigate to Validations | ||
| 3. Run | ||
|
|
||
| pod install | ||
| 4. Open the Validations.xcworkspace file using xcode | ||
| 5. Build and run using command + R. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we create and ship the files for this sample for them instead of forcing them to make the directory and files themselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because credentials file will not be in the
Samples folder. Here we are usingcredentials.jsonfile for generating bearer token. Which the user need to keep in the separate folder createdbearer-token-generatorand this folder will not be in this repo since it is completely node project which is used for generaton ofendpoint of token generator.