Skip to content

Commit

Permalink
feat: Adds Android SDK docs (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhudec authored Jan 4, 2023
1 parent 7f205e4 commit 9d36210
Show file tree
Hide file tree
Showing 17 changed files with 733 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ We will use [Terraform](https://www.terraform.io/) to provision Basis Theory res

## Creating the Inbound Proxy

In order to listen to API requests, we will create a Proxy that sits between the Client and your Server. We will assume these requests don't contain any sensitive information, so we will pass them through to the Server, which will respond with tokenized data. The Proxy will then [transform](/docs/api/proxies/#proxy-transform-object) the Server response to detokenize it and respond to the Client with the plaintext data.
In order to listen to API requests, we will create a Proxy that sits between the Client and your Server. We will assume these requests don't contain any sensitive information, so we will pass them through to the Server, which will respond with tokenized data. The Proxy will then [transform](/docs/api/proxies#proxy-transform-object) the Server response to detokenize it and respond to the Client with the plaintext data.

<SequenceDiagram width="100%" height="auto" />

Expand Down Expand Up @@ -253,7 +253,7 @@ This will create a application with the following [Access Controls](/docs/concep

#### Tokenization

Call the [Create Token](/docs/api/tokens/#create-token) token endpoint, using the key from the previous step:
Call the [Create Token](/docs/api/tokens#create-token) token endpoint, using the key from the previous step:

```bash showLineNumbers
curl "https://api.basistheory.com/tokens" \
Expand Down Expand Up @@ -326,12 +326,12 @@ You should see a JSON response like:

### What is Happening?

A secure HTTPS request is made to Basis Theory's Proxy endpoint. Basis Theory forwards the request to the specified destination URL, the [Echo Server](https://echo.basistheory.com/). Once the Server responds with a full echo body, the Proxy's transform response code looks for the token `id` to detokenize under `req.args.body.json.ssn` path. The Proxy detokenizes the SSN by [retrieving](/docs/api/tokens/#get-a-token) the token `data` and passing it in the response body to the Client.
A secure HTTPS request is made to Basis Theory's Proxy endpoint. Basis Theory forwards the request to the specified destination URL, the [Echo Server](https://echo.basistheory.com/). Once the Server responds with a full echo body, the Proxy's transform response code looks for the token `id` to detokenize under `req.args.body.json.ssn` path. The Proxy detokenizes the SSN by [retrieving](/docs/api/tokens#get-a-token) the token `data` and passing it in the response body to the Client.

This allows you to share sensitive PII data to any Client, without touching the data and, therefore, keeping your systems out of PII regulation scope.

## Conclusion

Following this Blueprint enables you to meet regulatory requirements for storing and sharing sensitive PII by using Tokenization. This approach reliefs the burden of having to implement your own data encryption to protect customers privacy.

Have feedback or questions? Join us in our [Slack community](https://community.basistheory.com).
Have feedback or questions? Join us in our [Slack community](https://community.basistheory.com).
2 changes: 1 addition & 1 deletion docs/concepts/access-controls.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Application to satisfy your specific requirements by choosing the `Create Your O
#### Grant Multiple Systems Access Following the Principle of Least Privilege

A common use-case for Applications is to grant minimal access to multiple systems where each system is only authorized
to perform necessary operations and access a relevant subset of data within a [Tenant](./access-controls/#what-are-tenants).
to perform necessary operations and access a relevant subset of data within a [Tenant](./access-controls#what-are-tenants).
This could mean that one system is only allowed to collect Tokenized data, another system is allowed to read the data to
perform analytics, and a third system is only allowed to [Proxy](./what-is-the-proxy/) the data
to an integrated 3rd party but never access the raw data.
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/collect/collect-inbound-data-to-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ curl "https://api.basistheory.com/applications" \

We will [create a Proxy](/docs/api/proxies#create-a-proxy) capable of intercepting inbound calls to our API, tokenize part of the request, and send the modified request to our API.

The Basis Theory Proxy leverages a [request transform](/docs/api/proxies/#proxy-transform-object), which is executed in a secure Node.js 16 runtime. The following code will handle tokenizing the request:
The Basis Theory Proxy leverages a [request transform](/docs/api/proxies#proxy-transform-object), which is executed in a secure Node.js 16 runtime. The following code will handle tokenizing the request:

```javascript showLineNumbers
module.exports = async function (req) {
Expand Down Expand Up @@ -184,4 +184,4 @@ Now that you have your token, check out our guide on how to [send data to a thir

- [Send Date to 3rd Party](/docs/guides/share/send-data-to-third-party)
- [What are tokens?](/docs/concepts/what-are-tokens)
- [Collect and process cards](/docs/blueprints/cards/collect-and-process-cards)
- [Collect and process cards](/docs/blueprints/cards/collect-and-process-cards)
68 changes: 68 additions & 0 deletions docs/sdks/mobile/android/events.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
sidebar_label: Events
---

# Element Events

Each element type supports a standard set of events that can be subscribed to in order to receive
callbacks within your application.

## ChangeEvent

Raised whenever the element's value is changed.

### Schema

| Property | Type | Description |
|------------|----------------------|---------------------------------------------------------------------------------------------|
| isComplete | `Boolean` | Whether the element has been completely filled (as specified by the [mask](./options#mask)) |
| isEmpty | `Boolean` | Whether the element is empty |
| isValid | `Boolean` | The result of the [validator](./options#validator), or `true` if no validator is specified |
| details | `List<EventDetails>` | A list of [EventDetails](#eventdetails) included with this event |

### EventDetails

| Property | Type | Description |
|----------|----------|----------------------------------------------------|
| type | `String` | The type of data represented by this detail object |
| message | `String` | The content of this detail object |

### Usage

```kotlin
myElement.addChangeEventListener {
// handle event
}
```

## FocusEvent

Raised whenever the element receives focus.

### Schema

*Empty*

### Usage

```kotlin
myElement.addFocusEventListener {
// handle event
}
```

## BlurEvent

Raised whenever the element loses focus.

### Schema

*Empty*

### Usage

```kotlin
myElement.addBlurEventListener {
// handle event
}
```
112 changes: 107 additions & 5 deletions docs/sdks/mobile/android/index.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
sidebar_label: Android Elements
sidebar_position: 0
---

import { Alert, Alerts } from "@site/src/components/shared/Alert";
import { Alert } from "@site/src/components/shared/Alert";
import { GithubCard } from "@site/src/components/sdks/GithubCard";
import { SDK } from "@site/src/components/types";

Expand All @@ -23,8 +24,109 @@ Think about it as an isolated sandbox within your mobile application that your e
interact with, and which securely communicates with the Basis Theory Vault. Sensitive data is not directly exposed to
your application code, which keeps your mobile application out of compliance scope.

Here is how we make this possible:
Here's how we make this possible:

- Own your UX, by fully customizing how Android Elements are styled
- Use inputs and forms with ease
- Interact with Android Elements just like native elements
- [Install](#installation) our Android SDK into your mobile application
- Build forms using our **[Element](./types)** input components
- [Interact](./services#basistheoryelements) with the Basis Theory API using **Element** references, not plaintext data
- Own your UI/UX by fully customizing how **Elements** are [styled](./options#styling)

## Collect Sensitive Data

Data entered by your end users into **Elements** is tokenized and secured within Basis Theory's certified Vault.

Our SDKs provide several types of inputs to collect various types of data, such as the [CardNumberElement](./types#cardnumberelement)
for collecting credit card data and [TextElement](./types#textelement) for collecting arbitrary textual data.

Elements can be configured to support custom input masking, validation, and transformation rules to satisfy your use cases.

## Reveal Sensitive Data

Tokens stored within the Basis Theory Vault can be securely revealed to end users without accessing the plaintext
data directly within your application code.

<Alert>
The ability to reveal sensitive data on Android is not yet generally available. If you are interested in using this feature on Android,
please email us at <a href="mailto:info@basistheory.com?subject=Android SDK - Reveal">info@basistheory.com</a> to
join our early access program.
</Alert>

## Before You Begin

Basis Theory Android Elements require the use of an API Key associated with a **Public Application**, which only allows `token:create` and `token:update` permissions to mitigate the risk that these API keys may be publicly exposed within your frontend applications.

To create one, login into our [Portal](https://portal.basistheory.com) and create a new "Public" Application with the permissions you require.

## Installation

### Requirements

- Android 5.0+ (API level 21+)
- AndroidX

### Gradle

Add this dependency to your project's build file:

```groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.basis-theory.basistheory-android:lib:<version>'
}
```

The latest release version can be found in [GitHub](https://github.com/Basis-Theory/basistheory-android/tags).

## Basic Usage

Simply include one or more elements within your application's views:

```xml showLineNumbers
<com.basistheory.android.view.CardNumberElement
android:id="@+id/card_number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.basistheory.android.view.CardExpirationDateElement
android:id="@+id/expiration_date"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.basistheory.android.view.CardVerificationCodeElement
android:id="@+id/cvc"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
```

Then tokenize the user input by referencing these elements. This can be wired up in response to a
button click, or any other user action.

```kotlin showLineNumbers
val cardNumberElement = findViewById(R.id.card_number)
val cardExpirationDateElement = findViewById(R.id.expiration_date)
val cardVerificationCodeElement = findViewById(R.id.cvc)

val bt = BasisTheoryElements.builder()
.apiKey(myPublicApiKey)
.build()

runBlocking {
val tokenizeResponse = bt.tokenize(object {
val type = "card"
val data = object {
val number = cardNumberElement
val expiration_month = cardExpirationDateElement.month()
val expiration_year = cardExpirationDateElement.year()
val cvc = cardVerificationCodeElement
}
})

// send the tokens within tokenizeResponse to your backend
}
```

A full example Android app is included within the [example](https://github.com/Basis-Theory/basistheory-android/tree/master/example)
module within the GitHub repo or explore all the supported [Element Types](./types).
Loading

1 comment on commit 9d36210

@vercel
Copy link

@vercel vercel bot commented on 9d36210 Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.