PowerBuilder / Salesforce Platform APIs / OpenID Connect Dynamic Client Registration Endpoint
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_StrVal
string ls_Client_id
string ls_Client_secret
string ls_Registration_access_token
string ls_Registration_client_uri
integer li_Client_id_issued_at
integer li_Client_secret_expires_at
string ls_Token_endpoint_auth_method
string ls_Client_name
integer i
integer li_Count_i
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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"
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("redirect_uris[0]","http://localhost")
loo_Json.UpdateString("response_types[0]","code")
loo_Json.UpdateString("response_types[1]","token")
loo_Json.UpdateString("response_types[2]","id_token")
loo_Json.UpdateString("grant_types[0]","authorization_code")
loo_Json.UpdateString("grant_types[1]","implicit")
loo_Json.UpdateString("grant_types[2]","refresh_token")
loo_Json.UpdateString("application_type","web")
loo_Json.UpdateString("contacts[0]","abc@sf.com")
loo_Json.UpdateString("contacts[1]","ve7jtb@example.org")
loo_Json.UpdateString("client_name","Example Olivier")
loo_Http.SetRequestHeader("Content-Type","application/json")
// Adds the "Authorization: Bearer {{init_access_token}}" header.
loo_Http.AuthToken = "{{init_access_token}}"
loo_Http.SetRequestHeader("Accept","application/json")
loo_Resp = loo_Http.PostJson3("https://login.salesforce.com{{site}}/services/oauth2/register","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// 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
ls_Client_id = loo_JResp.StringOf("client_id")
ls_Client_secret = loo_JResp.StringOf("client_secret")
ls_Registration_access_token = loo_JResp.StringOf("registration_access_token")
ls_Registration_client_uri = loo_JResp.StringOf("registration_client_uri")
li_Client_id_issued_at = loo_JResp.IntOf("client_id_issued_at")
li_Client_secret_expires_at = loo_JResp.IntOf("client_secret_expires_at")
ls_Token_endpoint_auth_method = loo_JResp.StringOf("token_endpoint_auth_method")
ls_Client_name = loo_JResp.StringOf("client_name")
i = 0
li_Count_i = loo_JResp.SizeOfArray("redirect_uris")
do while i < li_Count_i
loo_JResp.I = i
ls_StrVal = loo_JResp.StringOf("redirect_uris[i]")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("response_types")
do while i < li_Count_i
loo_JResp.I = i
ls_StrVal = loo_JResp.StringOf("response_types[i]")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("grant_types")
do while i < li_Count_i
loo_JResp.I = i
ls_StrVal = loo_JResp.StringOf("grant_types[i]")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("contacts")
do while i < li_Count_i
loo_JResp.I = i
ls_StrVal = loo_JResp.StringOf("contacts[i]")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("scopes")
do while i < li_Count_i
loo_JResp.I = i
ls_StrVal = loo_JResp.StringOf("scopes[i]")
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
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}"
}
]
}