-
Notifications
You must be signed in to change notification settings - Fork 34
How To Get an Authentication Token for System Users
Use the following procedures to register and authenticate System Users to make API calls to IBM Food Trust™. This is a key step towards automating your data uploads to IBM Food Trust.
A System User is a automated program, or an application, that sends or receives data by specifying a Service ID/API Key token combination. A System User can be a combination of multiple programs, or applications, in which case they share the same token. Registering multiple System Users with IBM Food Trust can be useful for managing distinct workloads, such as processing certificates and sending messages, and to separate information types on your local system.
To configure a new System User, you must first create a new Service ID/API Key pair. You will then register the System User with IBM Food Trust by defining its Service ID and API key in the Users UI module. Once registered, the System User will generate an IBM Food Trust Service token, in order to make authenticated API calls, using the following sequence:
- Specify the API key to request an IBM Cloud IAM token.
- Exchange the IBM Cloud IAM token for an IBM Food Trust Service token, which contains the Service ID and password.
- Specify the Service token in the Authorization header of API calls to IBM Food Trust.
- Because Service tokens expire one hour after being issued, either renew the token before expiration or repeat this process to generate a new Service token.
Attention: The specific process and detailed steps are described below.
A one-time initial registration is required to allow a new System User to authenticate to IBM Food Trust. Only an Organization administrator for your organization can register System Users. The Organization administrator must first create a unique Service ID and API key pair for each System User, as follows:
- Log in to IBM Food Trust and select the Users module.
- Select System IDs and then click Add System ID:
- Enter a Name for your new System ID, and then click the text link to create a new Service ID on IBM Cloud:
- Log in to IBM Cloud using your IBMid (email address registered with IBM):
- Select the Service IDs tab from the left menu:
- Click the Create + button:
- Enter a Name and Description for your Service ID:
- Select the API Keys tab and click the Create + button:
- Enter a Name and Description for your API Key and click the Create + button:
-
ATTENTION! Click the eye icon and copy and save the API Key value to your local system! This is your only opportunity to save and record the API Key value, which you will need later for automation:
Your downloaded and saved API key (JSON) should look similar to the following example:
json
{
"name": "Solution API key",
"description": "My Solution API key",
"createdAt": "2018-05-03T16:00+0000",
"apiKey": "wZvu952...gcci"
}
- Close the API Key window. From the subsequent Manage Mysystem ID window, copy the Service ID value ServiceId-######:
- Return to the IBM Food Trust Add System ID dialog. Paste the Service ID value copied from the previous step into the Service ID field, and then click the Add System ID button:
- The new System ID will be displayed in your IBM Food Trust Users panel:
After you have registered the new Service ID, the System User must generate an IBM Cloud IAM token using the following steps (an automated process):
- Copies the following cURL command:
bash curl -X POST --header "Content-Type: application/x-www-form-urlencoded" --data "grant_type=urn:ibm:params:oauth:grant-type:apikey" --data "apikey=<API_KEY>"https://iam.cloud.ibm.com/identity/token
- Replaces
<API_KEY>
with the apiKey value from the JSON key file, and runs the command. - Receives a response similar to the following example:
{
"access_token" : "eyJraWQiOiIyMDE3M...",
"token_type" : "Bearer",
"expires_in" : 3600,
"expiration" : 1523646898
}
After obtaining an IBM Cloud IAM token, the System User must exchange it for an IBM Food Trust Service token:
Windows users: Use an application such as Cygwin to run the following curl commands.
- The System User copies the following cURL command:
bash curl -X POST -H 'Content-Type: application/json' -d 'IAM_RESP_BODY' https://food.ibm.com/ift/api/identity-proxy/exchange_token/v1/organization/{ProductionOrganizationId}
- The System User replaces
IAM_RESP_BODY
with the IBM Cloud IAM JSON object ("access_token" value) returned from the previous Obtain an IBM Cloud IAM token step. - The System User replaces
{organizationId}
with the Organization ID and runs the command:
Example: (expanded JSON)
curl - X POST - H 'Content-Type: application/json' - d '
{
"access_token": "eyJraWQ...",
"refresh_token": "J1AV0...",
"token_type": "Bearer",
"expires_in": 3600,
"expiration": 1525367304
}
' https://food.ibm.com/ift/api/identity-proxy/exchange_token/v1/organization/38d1...
Attention: The Organization ID is available from the SYSTEM IDS tab in the Users Module:
- The System User receives a response similar to the following example:
{ "onboarding_token" : "eyJhbGciOiJSUzI1NiIsInR...", }
- In the Authorization header of API calls, the System User specifies the onboarding_token key (in the JSON object returned by the command), as Bearer <token>. The token expires three hours after being issued:
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR...
Both the IBM Cloud IAM token and the IBM Food Trust Service token are encoded with an expiration time. During the token exchange, the expiration time is copied from the IBM Cloud IAM token and applied to the IBM Food Trust Service token, so they will both expire at the same time.
If an expired IBM Cloud IAM token is sent with an exchange token request, it will be rejected. If an expired IBM Food Trust Service token is submitted with an API call, it will be rejected.
The following code samples create an IBM Cloud IAM token and exchange it for an IBM Food Trust Service token. You can use these examples to configure automation:
To resolve issues with System User configuration, use the following steps:
Issue: Receiving a 404 response when exchanging an IBM Cloud IAM token for an IBM Food Trust Service token:
Example Response:
{
“ok”: false,
“statusCode”: 404,
“error”: “User Id: {SERVICE_ID} not found with solution Id: {SOLUTION_ID} and organization Id: {ORGANIZATION_ID}”
}
Action:
-
Verify that the Service ID is registered as a System User in the IBM Food Trust Users module.
If the System ID is not registered, follow the instructions to Configure a System User. -
Verify that the correct URL is being targeted in the CURL command: Command:
curl -X POST -H 'Content-Type: application/json' -d 'IAM_RESP_BODY' https://food.ibm.com/ift/api/identity-proxy/exchange_token/v1/organization/{ProductionOrganizationId}
-
Verify that the correct Organization ID is being specified in the CURL command. There are separate Organization IDs for each corresponding zone. For example, if targeting the Integration zone, you must provide the Integration zone Organization Id. Again, if the Organization ID is unknown for the corresponding zone, it can be found in the
SYSTEM IDS
tab under theUser Management
section of the UI.
WELCOME!
Modules
Membership
Languages
Browsers
ONBOARDING
Onboarding Steps
Data Requirements
Data Types
Supplier Data
Payload Data
Insights Data
HOW-TO
Join by Invitation
Log in as New User
Authenticate Human Users
Authenticate System Users
Java Sample
Typescript Sample
IIB Sample
Assign User Roles
Upload Data
Automate Data Upload
Convert Spreadsheets
Convert Data
Whitelist Custom URLs
APIs-Swagger
Connector API
Documents API
Converter API
Trace API
Insights API
APIs-Usage
APIs
Insights API
Insights API Usage
Trace API
Connector API Errors
API Error Codes
REFERENCE
GS1
GS1 Identifier Reuse
Authentication
Identifiers
Message Codes
Cryptographic
Signatures
Signature Header
Access Control
Firewall Settings
XML to JSON
EPCIS Aggregation Add
EPCIS Aggregation Delete
EPCIS Object Add
EPCIS Object Delete
EPCIS Object Observed
EPCIS Transformation
Purchase Order
Despatch Advice
Receiving Advice
Master Data Item
Master Data Facility
Standard Business
Document Header