🕐 5 min read
The OAuth boilerplate is a connector that ingests JSON data with ingestDataRows Fetch API and built-in TACO data parser.
To create your OAuth connector, we recommend that you first create a boilerplate OAuth connector and edit the generated files. It’s easier to get all the files and directory structure your connector needs by just using an existing example.
To create your OAuth connector, do the following steps.
Enter the following command to create the connector:
taco create my-oauth-connector --boilerplate oauth
This creates a directory with the earthquake data boilerplate code, which is included with the toolkit.
my-oauth-connector
directory.
cd my-oauth-connector
Build the connector by entering the following command:
taco build
This command clears any previous or existing build caches, then installs the dependencies, then builds the frontend code and the backend code (handlers), then copies the connector.json file (the configuration file).
In your new OAuth connector directory, find and open the connector.json
file.
{
"name": "my-oauth-connector",
"displayName": "OAuth Sample Connector",
"version": "1.0.0",
"tableau-version": {
"min": "2023.3"
},
"vendor": {
"name": "vendor-name",
"support-link": "https://vendor-name.com",
"email": "support@vendor-name.com"
},
"auth": {
"type": "oauth2",
"oauth": {
"clientIdDesktop": "[Your client id]",
"clientSecretDesktop": "[Your client secret]",
"redirectUrisDesktop": [
"http://localhost:55555/Callback"
],
"authUri": "[Your auth URI]",
"tokenUri": "[Your token URI]",
"userInfoUri": "[Your API user info URI]",
"scopes": [
"Scope 1",
"Scope 2"
],
"capabilities": {
"OAUTH_CAP_FIXED_PORT_IN_CALLBACK_URL": true,
"OAUTH_CAP_CLIENT_SECRET_IN_URL_QUERY_PARAM": true,
"OAUTH_CAP_PKCE_REQUIRES_CODE_CHALLENGE_METHOD": true,
"OAUTH_CAP_REQUIRE_PKCE": true
},
"accessTokenResponseMaps": {
"ACCESSTOKEN": "access_token",
"REFRESHTOKEN": "refresh_token",
"access-token-issue-time": "issued_at",
"access-token-expires-in": "expires_in",
"username": "username"
}
}
},
"permission": {
"api": {
"https://*.example.com/": [
"GET",
"POST"
]
}
},
"window": {
"height": 900,
"width": 770
}
}
Make the following changes:
Change the general properties.
Name | Value |
---|---|
name | Your connector’s directory name |
displayName | Your connector’s name. This is the name that appears in the Tableau connectors area. |
version | Your connector’s version |
min | The earliest Tableau version your connector supports |
Change the company properties.
Name | Value |
---|---|
vendor.name | Your company name |
vendor.support-link | Your company’s URL |
vendor.email | Your company’s email |
Change the permissions.
Name | Value |
---|---|
permission.api | The URI for the API that the connector is allowed to access, along with the methods (POST, GET, PUT, PATCH, DELETE) that the connector is allowed to use. |
Set the authentication values.
Name | Value |
---|---|
auth.type | Set to oauth2 |
auth.oauth | For configuration information, see Configuring for OAuth |
For more information about authentication, see the Authentication section in the Considerations for Building Your Connector topic.
Change the HTML pane size.
Name | Value |
---|---|
window.height | The height of the connector HTML pane |
window.width | The width of the connector HTML pane |
When you open a web data connector in Tableau, the connector displays an HTML page that links to your code and to your connector’s handlers. Optionally, this page can also display a user interface (UI) for your users to select the data that they want to download.
The /app/components/ConnectorView.tsx
file is the main component for the connector UI. You can modify or replace this file based on your connector UI requirements.
The /app/components/useConnector.ts
file contains a custom React hook that abstracts common connector object operations. * The hook creates a connector object. A component can:
isInitializing
)handleSubmit
)The following is the code in userConnector.ts
file for the connector creation.
const [connector] = useState<Connector>(
() =>
new Connector(
(connector: Connector) => {
Logger.info('Connector initialized.')
const oauthCredentials = connector.oAuthCredentials
setConnectorState({ ...connectorState, oauthCredentials, isInitializing: false })
},
(_: Connector, error: Error) => {
Logger.error(`Connector Initialized Error: ${error.message}`)
setConnectorState({ ...connectorState, errorMessage: error.message, isInitializing: false })
}
)
)
If your data is complex and needs preprocessing, use the TACO Toolkit library to prepare your data.
The following is the default code that the /handlers/DataFetcher.ts
file uses to get the data:
import { Fetcher, FetchUtils, FetchOptions, DataRow, getOAuthHeader } from '@tableau/taco-toolkit/handlers'
interface User {
id: string
name: string
address: { street: string; state: string; country: string }
}
export default class DataFetcher extends Fetcher {
async *fetch({ secrets }: FetchOptions) {
// PLACEHOLDER: the url is NOT real endpoint.
// Replace them with actual endpoint for corresponding file type.
// Note: the permission setting in connector.json also needs to be updated accordingly.
const url = 'https://www.example.com/api/user'
const headers = getOAuthHeader(secrets)
const users = await FetchUtils.fetchJson(url, { headers })
// Convert JSON response into DataRow[] type
const rows: DataRow[] = users.map((user: User) => {
const {
id,
name,
address: { street, state, country },
} = user
return { id, name, street, state, country }
})
yield await FetchUtils.ingestDataRows(rows)
}
}
Enter these commands to build, pack, and run your new connector:
taco build
taco pack
taco run Desktop