SQL Server / Salesforce Platform APIs / OpenID Connect Dynamic Client Registration Endpoint
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- 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"
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'redirect_uris[0]', 'http://localhost'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'response_types[0]', 'code'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'response_types[1]', 'token'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'response_types[2]', 'id_token'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'grant_types[0]', 'authorization_code'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'grant_types[1]', 'implicit'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'grant_types[2]', 'refresh_token'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'application_type', 'web'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'contacts[0]', 'abc@sf.com'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'contacts[1]', 've7jtb@example.org'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'client_name', 'Example Olivier'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
-- Adds the "Authorization: Bearer {{init_access_token}}" header.
EXEC sp_OASetProperty @http, 'AuthToken', '{{init_access_token}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://login.salesforce.com{{site}}/services/oauth2/register', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @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
DECLARE @strVal nvarchar(4000)
DECLARE @client_id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @client_id OUT, 'client_id'
DECLARE @client_secret nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @client_secret OUT, 'client_secret'
DECLARE @registration_access_token nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @registration_access_token OUT, 'registration_access_token'
DECLARE @registration_client_uri nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @registration_client_uri OUT, 'registration_client_uri'
DECLARE @client_id_issued_at int
EXEC sp_OAMethod @jResp, 'IntOf', @client_id_issued_at OUT, 'client_id_issued_at'
DECLARE @client_secret_expires_at int
EXEC sp_OAMethod @jResp, 'IntOf', @client_secret_expires_at OUT, 'client_secret_expires_at'
DECLARE @token_endpoint_auth_method nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @token_endpoint_auth_method OUT, 'token_endpoint_auth_method'
DECLARE @client_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @client_name OUT, 'client_name'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'redirect_uris'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'redirect_uris[i]'
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'response_types'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'response_types[i]'
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'grant_types'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'grant_types[i]'
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'contacts'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'contacts[i]'
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'scopes'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'scopes[i]'
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
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}"
}
]
}