How To
Summary
OAuth is an open standard for access delegation. It is used as a way for Internet users to grant websites or applications access to information on other websites without giving them passwords. This mechanism permits the users to share information about their accounts with third-party applications or websites.
Objective
Steps
Using OAuth for REST calls
OAuth for REST calls can be used to run decision services, or use Rule Execution Server, Decision Center REST APIs or the user management REST API. To use OAuth for REST calls, follow these steps:
curl -k -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"requested_lifetime": <time_in_seconds>}' 'https://<instance_id>.bpm.ibmcloud.com/instance/services/csrf_token' -v -u '<fid_name>:<fid_password>'
{"expiration"<time_in_seconds>","csrf_token":"***"}
curl -k -X POST --header 'Authorization: Basic ***' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'IBM-CSRF-TOKEN: <IBM_TOKEN>' -d '{"id_prefix":"<oauth_client_id_prefix>", "description": "<my_description>"}' https://<instance_id>.bpm.ibmcloud.com/instance/services/credentials/oauth_clients
{"description":"*<my_description> ","creator":"<user_email>","client_id":" <oauth_client_id_prefix>.oac@<tenant_id>","client_secret":"***","creation_time":"YYYY-MM-DDTHH:MM:SS.MSSZ"}
curl -k -X POST -H 'content-type: application/x-www-form-urlencoded' -d grant_type=password -d client_id=<oauth_client_id> -d client_secret=<oauth_client_secret> -d username=<fid_name> -d password='<fid_password>' https://www.bpm.ibmcloud.com/mga/sps/oauth/oauth20/token
{"access_token":"***","refresh_token":"***","scope":"","token_type":"bearer","expires_in":<time_in_seconds_specified_in_request>}
Task 2: Invoking REST APIs
Now, you can invoke Operational Decision Manager on Cloud REST APIs by using the generated tokens. The following examples use the Miniloan project in the Operational Decision Manager on Cloud getting started tutorial. All requests to REST APIs are described in the dedicated sections of the Operational Decision Manager on Cloud Knowledge Center.
Note that if the temporary access token is invalid or expired, the call returns the HTTP response code 302.
curl -k -X GET --header 'Accept: application/json' --header 'Authorization: Bearer <token_bearer>' 'https://<instance_id>.bpm.ibmcloud.com/odm/dev/decisioncenter-api/v1/decisionservices/<decision_service_id>'
{"id":"<decision_service_id>","internalId":"brm.RuleProject:XX:XX","name":"Miniloan Service","buildMode":"DecisionEngine","advancedProperties":null}
curl --location --request POST 'https://<instance_id>.bpm.ibmcloud.com/odm/dev/DecisionService/rest/Miniloan/1.0/Miniloan_ServiceRuleset' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Authorization: Bearer <token_bearer>' \
--data-raw '{"loan": {"duration": 240,"amount": 499999, "yearlyInterestRate": 0.05},"borrower": {"creditScore": 600, "name": "string", "yearlyIncome": 80000}}'
{"__DecisionID__":"87d53382-fee5-49d7-993f-7c9e10f3c9390","loan":{"amount":499999,"duration":240,"yearlyInterestRate":0.05,"yearlyRepayment":39597,"approved":false,"messages":["Too big Debt-To-Income ratio"]}}
curl -k --header 'Authorization: Bearer ***' --request GET 'https://<instance_id>.bpm.ibmcloud.com/odm/dev/res/api/v1/ruleapps?count=true '
curl -k -X GET --header 'Accept: application/json' --header 'Authorization: Bearer ***' --header 'IBM-CSRF-TOKEN: eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MDU2MzYxNDAsInN1YiI6InN1cmVzaGFwcGNsb3VkQGdtYWlsLmNvbSJ9.cdI9Hs3P1ARbxfHAJ64lxYiz70LoH_Y8zvBJbxt2TeE' 'https://<instance_id>.bpm.ibmcloud.com:443/instance/services/users?sort=user_id%3Aasc'
{
"users": [
{
"email": "alex@acme.corp",
"user_id": "alex@acme.corp",
"base_dn": "ou=users,O=IBM,c=UK",
"given_name": "Alex",
"family_name": "Demo"
},
{
"email": "acme2oauth.fid@t1000",
"user_id": "acme2oauth.fid @t1000",
"base_dn": "ou=users,O=IBM,c=UK"
}
],
"total_size": 2
}
Once a token is created (see task 1), do the following actions:
- Refresh token:
The tokens expire every 30 minutes. Applications must use this endpoint to refresh tokens.
curl -k -X POST -H 'content-type: application/x-www-form-urlencoded' -d grant_type=refresh_token -d refresh_token=<refresh_token> -d client_id=<oauth_client_id> -d client_secret=<oauth_client_secret> https://<instance_id>.bpm.ibmcloud.com/mga/sps/oauth/oauth20/token
{
"access_token": "***",
"refresh_token": "***",
"scope": "",
"token_type": "bearer",
"expires_in": 179
}
- Revoke token:
It's a good practice to revoke the tokens when the client application finishes processing. Use this endpoint to revoke the tokens, first the refresh token and then the access token.
curl -k -X POST -H 'content-type: application/x-www-form-urlencoded' -d client_id=<oauth_client_id> -d client_secret=<oauth_client_secret> -d token= <token_bearer> https://www.blueworkscloud.com/mga/sps/oauth/oauth20/revoke
Note: The response to this request is empty but the expected HTTP return code is 200.
Task 4: Adding an external Rule Execution Server by using OAuth to connect an Operational Decision Manager on Cloud Decision Center
OpenID Connect (OIDC) is an authentication framework that is built on top of the OAuth 2.0 protocol. Operational Decision Manager servers use OIDC to verify a user's identity with an OpenID Connect Provider, and to authorize access to the Operational Decision Manager applications and APIs.
Prerequisites
- Operational Decision Manager on Cloud Decision Center that is Decision Center
- Operational Decision Manager Rule Execution Server that is
- Log in to the source Business console.
- Open the Administration tab.
- Open the Servers subtab.
- Create an oauth_providers.json configuration file by using the following JSON template and the client created in step 1:
{
"providers": [
{
"name": "<name>",
"grantType": "password",
"authorizationURL": "https://www.bpm.ibmcloud.com/mga/sps/oauth/oauth20/authorize",
"tokenURL": "https://www.bpm.ibmcloud.com/mga/sps/oauth/oauth20/token",
"scope": "openapi",
"clientId": "<client_id>",
"clientSecret": "<client_secret>"
}
]
}

- Click the Add button
.
- Specify the URL of the destination Rule Execution Server. Toggle the Use OpenID Connect button to on, and select the correct configuration. The user name and password fields should correspond to the user or service credentials of the target Rule Execution Server:
- Click Create.

Additional Information
Related Information
Document Location
Worldwide
Was this topic helpful?
Document Information
More support for:
IBM Operational Decision Manager on Cloud
Software version:
All Versions
Document number:
6373626
Modified date:
09 November 2022
UID
ibm16373626