Can a published resource in TIBCO Data Virtualization be securely accessed using Python via OAuth 2.0?

Can a published resource in TIBCO Data Virtualization be securely accessed using Python via OAuth 2.0?

book

Article ID: KB0070334

calendar_today

Updated On:

Products Versions
TIBCO Data Virtualization 8.7, 8.6

Description

In the given scenario, Anaconda Python, an open-source platform, is utilized for scripting and executing code in Python for this KB.

Prerequisites:

  1. Set up OAuth configuration on TIBCO Data Virtualization.
  2. Ensure the Requests library is installed (pip install requests).
  3. Access the OAuth configuration details for the target API, including the token_url, client_id, client_secret, and resource.

Environment

All Supported Environment

Resolution

 import requests # URL and payload for obtaining access token token_url = "https://login.microsoftonline.com/81b0c56e-5c46-4d31-a99f-c43d1613fe7d/oauth2/token" headers = {     "content-type": "application/x-www-form-urlencoded" } data = {     "grant_type": "client_credentials",     "client_id": "provide the client ID here",     "client_secret": "provide the client secret here",     "resource": "provide the resource details here" } # Obtaining access token token_response = requests.post(token_url, data=data) token_data = token_response.json() access_token = token_data['access_token'] # URL for accessing the API api_url = "provide the API URL hosted in TDV here" myHeaders = {     'Authorization': f'Bearer {access_token}' } # Making GET request to the API response = requests.get(api_url, headers=myHeaders) print(response.text)
 
Below is a screenshot of the code and its output:
image.png
 
image.png

Issue/Introduction

This article demonstrates Python code functioning as a client app. It obtains the access token and also makes a call to the published resource in TDV to retrieve the results.