Creating Admin Credentials for API Access in the SAP Customer Data Platform
Objective
After completing this lesson, you will be able to create and manage administrative credentials required for accessing the SAP Customer Data Platform API.
Introduction
In this lesson, you will learn how to create credentials necessary to consume the REST API of the SAP Customer Data Platform. Since all SAP Customer Data Platform APIs need to be authenticated, we will explore the available options to ensure that the API calls you perform will have the proper authorization setup in place.
Providing Credentials for API Access
Prerequisites
In this section, we will explain how to create credentials for API access in three main steps:
Configuring a New Server Application
Using the User and Secret Keys
Using an OAuth 2.0 JWT Bearer Token
Before starting:
Follow the steps below
Copy the code phrases, keys and other placeholder values to a text file.
Use the copy icon located on the right side of each textbox to ensure you've copied the full value of the corresponding key.
Before starting, make sure that you:
Familiarize yourself with the use of Unix command line utilities, such as cURL.
Have access to the SAP Customer Data Platform Console and create or use a Business Unit already loaded with customer Profile and Order data.
Throughout this course, the keys we'll be using for authentication (user, secret, and private) are shown in plain text, to familiarize you with their format. None of these keys remain valid, as they were deleted prior to the publication of this course.
Step 1. Configuring a New Server Application
1.1 To consume the SAP Customer Data Platform APIs, we need first to create and then edit a Server Application using the console, which will provision the keys necessary to authenticate the REST API calls.
1.2 You have two options for authenticating API calls. The first is using a pair of Server Application User and Secret Keys. The second allows you to generate an OAuth 2.0-compliant JWT-based Bearer Token by supplying a Server Application’s RSA Private Key.
Start by copying the values of User Key, Secret Key, and Private Key into a new text file. We will call it the placeholder file during this lesson since we’ll use the values we store there to replace placeholders in the templates on which we’ll base our API calls. Assign a placeholder name, such as USER_KEY, SECRET_KEY, or PRIVATE_KEY, to each key value. From that point forward, every time the instructions mention the placeholder name, you’ll be ready to replace that placeholder with the appropriate value.
1.3 In Destination Purposes, you can choose which Processing Purposes the API caller will have access to when consuming the REST APIs using credentials based on the Server Application’s keys. This step is important to ensure data privacy compliance when accessing your customer data.
Configuring the Server Application
In the following video, we will use the SAP Customer Data Platform Console to perform a step-by-step tutorial on how to configure a new Server Application to supply the keys for API access.
Video Summary
In this video, we configured a Source Application using the SAP Customer Data Platform Console with the following steps:
Create a new server application
Retrieve and copy API keys
Set Destination Purposes
Save configuration
Step 2. Using the User and Secret Keys
You can authenticate a call to the SAP Customer Data Platform APIs by appending the User Key and Secret Key values to the requesting REST API URL’s query string. Better yet, for improved security, you can store the userKey and secret in the body of the HTTP request by using the --data argument to the cURL command.
2.1 Let’s say you want to query all customer profiles using a REST API. The call can be authenticated by storing the key/value pairs userKey and secretKey in the body of the HTTP request. The cURL template for such a call is:
Calling an SAP Customer Data Platform REST API using the User and Secret Key values - Video
In the following video, we follow the steps to use the previously generated User Key and Secret Key values to authenticate a call to an SAP Customer Data Platform REST API endpoint.
Video Summary
In this video, we used a User and Secret Key to authenticate a call to an SAP Customer Data Platform REST API endpoint.
Step 3. Using an OAuth 2.0 JWT Bearer Token
You can authenticate a call to the SAP Customer Data Platform REST APIs by using an OAuth 2.0 JWT Bearer Token generated from the Server Application’s RSA Private Key value. In this case, the Bearer Token value needs to be copied into the Authorization HTTP Header.
There are two ways that you can build this Bearer Token.
The first is to use the User Key and Secret Key to perform a POST call to the OAuth 2.0 token endpoint, which will return an Access Token that will be valid for authenticating REST API calls during the ensuing 10 minutes.
The second way requires building a JWT Bearer Token by providing the User Key, Private Key, a nonce value, and the current timestamp in Unix epoch format.
3.1 Retrieve a JWT Bearer Token from the OAuth 2.0 token endpoint.
3.1.1 Let’s perform a POST REST call to the SAP Customer Data Platform OAuth 2.0 token endpoint to retrieve a ready to use JWT Bearer Token. The cURL command template for such call is:
3.1.2 After replacing the USER_KEY and SECRET_KEY placeholders with their respective values, we got the cURL command below. When executed, it returns a ready-to-use Bearer Token in the response payload body:
3.1.3 After executing this script, copy from the returned JSON payload the access_token attribute value to your text file, identified as the BEARER_TOKEN_1 placeholder. You will use it in the next section.
3.2 Building a JWT Bearer Token using the Private Key value.
3.2.1 Let’s start by building a bash script that will leverage some standard command line utilities to generate our JWT Bearer Token. Define a PK bash variable using the template below:
Code Snippet
123456
PK=$(cat <<-EOM
PRIVATE_KEY
EOM
)
3.2.2 Now replace the PRIVATE_KEY placeholder with its value from your text file:
3.2.3 The HEADER variable is a JSON block containing the JWT hash algorithm (RS256), the Key Id (the USER_KEY value of the CDP Server Application), and the token type (JWT). Here is the template for the HEADER variable.
3.2.5 The following block contains the PAYLOAD variable of our JWT, which is formed by another JSON block containing the Issued At attribute, set to the value of the current Unix Epoch timestamp, and the JWT Id holding a nonce value:
3.2.6 The HEADER_PAYLOAD variable contains the concatenated values of HEADER and PAYLOAD, each encoded in Base 64 and separated by a period to conform to the JWT tokenization format.
3.2.7 The next line is where the JWT Header and Payload gets hashed with the Private Key contents to form the signature part of the JWT token. After that, its value gets encoded to Base 64 and stored into the SIGNATURE variable.
3.2.8 Finally, the BEARER_TOKEN joins the values of HEADER_PAYLOAD and SIGNATURE, once again separated by a period character. Our OAuth 2.0 JWT Bearer Token is complete and ready to be used for authenticating an SAP Customer Data Platform API call.
3.2.10 After executing the full script you built by following the steps 3-b-i through 3-b-viii, store the result as the BEARER_TOKEN_2 placeholder in your text file. You’ll use it in the next section.
3.3 Calling an SAP Customer Data Platform REST API using an OAuth 2.0 JWT Bearer Token
3.3.1 Now let’s see how to use the Bearer Token to authenticate a REST API call to SAP Customer Data Platform. For this quick test, let’s use the REST API call that returns all customer profiles. The cURL command template for this call is:
Code Snippet
123456
curl --request GET \
--url 'https://cdp.eu5.gigya.com/api/businessunits/4_iNfbhGDrBGciUrxckeBfJA/views/HAPxPF10AHr1bASCaGU_dQ/customers' \
--data-urlencode purposeIds=HFZPPZxxFQUebd3ksLoTaQ \
--data-urlencode query="SELECT * FROM Profiles" \
--header 'Authorization: Bearer BEARER_TOKEN'
3.3.2 You can replace the BEARER_TOKEN placeholder by the value of either BEARER_TOKEN_1 or BEARER_TOKEN_2 (they will both work). After replacing the BEARER_TOKEN symbol with an actual value, we got the following cURL command:
Code Snippet
123456
curl --request GET \
--url 'https://cdp.eu5.gigya.com/api/businessunits/4_iNfbhGDrBGciUrxckeBfJA/views/HAPxPF10AHr1bASCaGU_dQ/customers' \
--data-urlencode purposeIds=HFZPPZxxFQUebd3ksLoTaQ \
--data-urlencode query="SELECT * FROM Profiles" \
--header 'Authorization: Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkMyMzc4RUMyNTdDMkI3Mzc5NTYzNzI2RDU4QUM1Mzg0NTY3MUUyNDJCNTZDMkM0NTRCMEU2QjBBNUMzN0Q0RDkiLCJ0eXAiOiJhdCtqd3QifQ.eyJhdWQiOiJodHRwczovL2FwaS5naWd5YS5jb20iLCJzdWIiOiJBSTMyWFRhaXpDZ2IiLCJjbGllbnRfaWQiOiJBSTMyWFRhaXpDZ2IiLCJzY29wZSI6ImFwcGxpY2F0aW9uX2tleSIsImNsaWVudF9uYW1lIjoiQ0RQIGlkOiBITi1YR0pXLVFuYWtIbWFfT01MeWRRIiwibmJmIjoxNzI5MzI2NTkzLCJleHAiOjE3MjkzMjcxOTMsImlhdCI6MTcyOTMyNjU5MywiaXNzIjoiaHR0cHM6Ly9vYXV0aDIuZ2lneWEuY29tIn0.JE2vYErDkFj0ve0mLArj4ThEg_z3pzFqKq-7X83h1iX2Hbomf8g7RD8G1cHYdv3QivOYkWqJnF5dj_EldZCrsg'
After executing it, you will see a list of customer profiles in the returned JSON payload.
NOTE: Just keep in mind that the SAP Customer Data Platform Bearer Tokens expire 10 minutes after they’re created.
Calling an SAP Customer Data Platform API using an Oauth 2.0 JWT Bearer Token
In the following video, we show step by step how to use the previously generated RSA Private Key value to generate an OAuth 2.0-compliant JWT Bearer Token that can be used to authenticate a call to an SAP Customer Data Platform REST API endpoint.
Video Summary
In this video, we used an RSA Private Key value to build a Bearer Token to authenticate a call to an SAP Customer Data Platform REST API endpoint.
Lesson Summary
In this lesson, we explored the authorization setup for API access to SAP Customer Data Platform by configuring a Server Application that supplies different keys used to authenticate REST API calls. You can either authenticate your calls using User and Secret Key value pairs, or else rely on OAuth 2.0-compliant JWT Bearer token access. Step by step videos were provided showing how to configure the Server Application and implement the two different ways to authenticate your REST API calls to the SAP Customer Data Platform.