Foxpro / Salesforce Platform APIs / OpenID Connect Dynamic Client Registration Endpoint
Back to Collection Items
LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcStrVal
LOCAL lcClient_id
LOCAL lcClient_secret
LOCAL lcRegistration_access_token
LOCAL lcRegistration_client_uri
LOCAL lnClient_id_issued_at
LOCAL lnClient_secret_expires_at
LOCAL lcToken_endpoint_auth_method
LOCAL lcClient_name
LOCAL i
LOCAL lnCount_i
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loHttp = CreateObject('Chilkat.Http')
* Use this online tool to generate code from sample JSON: Generate Code to Create JSON
* The following JSON is sent in the request body.
* {
* "redirect_uris": [
* "http://localhost"
* ],
* "response_types": [
* "code",
* "token",
* "id_token"
* ],
* "grant_types": [
* "authorization_code",
* "implicit",
* "refresh_token"
* ],
* "application_type": "web",
* "contacts": [
* "abc@sf.com",
* "ve7jtb@example.org"
* ],
* "client_name": "Example Olivier"
* }
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("redirect_uris[0]","http://localhost")
loJson.UpdateString("response_types[0]","code")
loJson.UpdateString("response_types[1]","token")
loJson.UpdateString("response_types[2]","id_token")
loJson.UpdateString("grant_types[0]","authorization_code")
loJson.UpdateString("grant_types[1]","implicit")
loJson.UpdateString("grant_types[2]","refresh_token")
loJson.UpdateString("application_type","web")
loJson.UpdateString("contacts[0]","abc@sf.com")
loJson.UpdateString("contacts[1]","ve7jtb@example.org")
loJson.UpdateString("client_name","Example Olivier")
loHttp.SetRequestHeader("Content-Type","application/json")
* Adds the "Authorization: Bearer {{init_access_token}}" header.
loHttp.AuthToken = "{{init_access_token}}"
loHttp.SetRequestHeader("Accept","application/json")
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpJson("POST","https://login.salesforce.com{{site}}/services/oauth2/register",loJson,"application/json",loResp)
IF (lnSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
RELEASE loResp
CANCEL
ENDIF
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loHttp
RELEASE loJson
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF
* Sample JSON response:
* (Sample code for parsing the JSON response is shown below)
* {
* "client_id": "<client_id>",
* "client_secret": "<client_secret>",
* "registration_access_token": "<token>",
* "registration_client_uri": "https://login.salesforce.com/services/oauth2/register/<client_id>",
* "client_id_issued_at": <timestamp>,
* "client_secret_expires_at": 0,
* "token_endpoint_auth_method": "client_secret_post",
* "redirect_uris": [
* "http://localhost"
* ],
* "response_types": [
* "code",
* "token",
* "id_token"
* ],
* "grant_types": [
* "authorization_code",
* "hybrid_auth_code",
* "implicit",
* "refresh_token"
* ],
* "contacts": [
* "abc@sf.com"
* ],
* "client_name": "Sample Customer",
* "scopes": [
* "openid",
* "refresh_token",
* "id",
* "api"
* ]
* }
* Sample code for parsing the JSON response...
* Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
lcClient_id = loJResp.StringOf("client_id")
lcClient_secret = loJResp.StringOf("client_secret")
lcRegistration_access_token = loJResp.StringOf("registration_access_token")
lcRegistration_client_uri = loJResp.StringOf("registration_client_uri")
lnClient_id_issued_at = loJResp.IntOf("client_id_issued_at")
lnClient_secret_expires_at = loJResp.IntOf("client_secret_expires_at")
lcToken_endpoint_auth_method = loJResp.StringOf("token_endpoint_auth_method")
lcClient_name = loJResp.StringOf("client_name")
i = 0
lnCount_i = loJResp.SizeOfArray("redirect_uris")
DO WHILE i < lnCount_i
loJResp.I = i
lcStrVal = loJResp.StringOf("redirect_uris[i]")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("response_types")
DO WHILE i < lnCount_i
loJResp.I = i
lcStrVal = loJResp.StringOf("response_types[i]")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("grant_types")
DO WHILE i < lnCount_i
loJResp.I = i
lcStrVal = loJResp.StringOf("grant_types[i]")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("contacts")
DO WHILE i < lnCount_i
loJResp.I = i
lcStrVal = loJResp.StringOf("contacts[i]")
i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("scopes")
DO WHILE i < lnCount_i
loJResp.I = i
lcStrVal = loJResp.StringOf("scopes[i]")
i = i + 1
ENDDO
RELEASE loHttp
RELEASE loJson
RELEASE loResp
RELEASE loSbResponseBody
RELEASE loJResp
Curl Command
curl -X POST
-H "Content-Type: application/json"
-H "Accept: application/json"
-H "Authorization: Bearer {{init_access_token}}"
-d '{
"redirect_uris": [
"http://localhost"
],
"response_types": [
"code",
"token",
"id_token"
],
"grant_types": [
"authorization_code",
"implicit",
"refresh_token"
],
"application_type": "web",
"contacts": [
"abc@sf.com",
"ve7jtb@example.org"
],
"client_name": "Example Olivier"
}'
https://login.salesforce.com{{site}}/services/oauth2/register
Postman Collection Item JSON
{
"name": "OpenID Connect Dynamic Client Registration Endpoint",
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "Accept",
"value": "application/json",
"type": "text"
},
{
"key": "Authorization",
"value": "Bearer {{init_access_token}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"redirect_uris\": [\n \"http://localhost\"\n ],\n \"response_types\": [\n \"code\",\n \"token\",\n \"id_token\"\n ],\n \"grant_types\": [\n \"authorization_code\",\n \"implicit\",\n \"refresh_token\"\n ],\n \"application_type\": \"web\",\n \"contacts\": [\n \"abc@sf.com\",\n \"ve7jtb@example.org\"\n ],\n \"client_name\": \"Example Olivier\"\n}"
},
"url": {
"raw": "{{url}}{{site}}/services/oauth2/register",
"host": [
"{{url}}{{site}}"
],
"path": [
"services",
"oauth2",
"register"
]
}
},
"response": [
{
"name": "Successful OpenID Connect Dynamic Client Registration Endpoint",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{init_access_token}}"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"redirect_uris\": [\n \"http://localhost\"\n ],\n \"response_types\": [\n \"code\",\n \"token\",\n \"id_token\"\n ],\n \"grant_types\": [\n \"authorization_code\",\n \"implicit\",\n \"refresh_token\"\n ],\n \"application_type\": \"web\",\n \"contacts\": [\n \"abc@sf.com\",\n \"ve7jtb@example.org\"\n ],\n \"client_name\": \"Sample Customer\"\n}"
},
"url": {
"raw": "{{url}}{{site}}/services/oauth2/register",
"host": [
"{{url}}{{site}}"
],
"path": [
"services",
"oauth2",
"register"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Date",
"value": "Thu, 16 Nov 2023 16:04:08 GMT"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=63072000; includeSubDomains"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "X-Robots-Tag",
"value": "none"
},
{
"key": "Cache-Control",
"value": "no-cache,must-revalidate,max-age=0,no-store,private"
},
{
"key": "Expires",
"value": "Thu, 01 Jan 1970 00:00:00 GMT"
},
{
"key": "Content-Type",
"value": "application/json;charset=UTF-8"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "{\n \"client_id\": \"<client_id>\",\n \"client_secret\": \"<client_secret>\",\n \"registration_access_token\": \"<token>\",\n \"registration_client_uri\": \"https://login.salesforce.com/services/oauth2/register/<client_id>\",\n \"client_id_issued_at\": <timestamp>,\n \"client_secret_expires_at\": 0,\n \"token_endpoint_auth_method\": \"client_secret_post\",\n \"redirect_uris\": [\n \"http://localhost\"\n ],\n \"response_types\": [\n \"code\",\n \"token\",\n \"id_token\"\n ],\n \"grant_types\": [\n \"authorization_code\",\n \"hybrid_auth_code\",\n \"implicit\",\n \"refresh_token\"\n ],\n \"contacts\": [\n \"abc@sf.com\"\n ],\n \"client_name\": \"Sample Customer\",\n \"scopes\": [\n \"openid\",\n \"refresh_token\",\n \"id\",\n \"api\"\n ]\n}"
}
]
}