Chilkat Online Tools

SQL Server / Salesforce Platform APIs / Web Server Flow 1

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

    DECLARE @queryParams int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'response_type', 'code'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'client_id', '{{clientId}}'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'redirect_uri', '{{redirectUrl}}'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'scope', 'full refresh_token'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://login.salesforce.com{{site}}/services/oauth2/authorize', @queryParams
    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 @queryParams
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams


END
GO

Curl Command

curl -G -d "response_type=code"
	-d "client_id=%7B%7BclientId%7D%7D"
	-d "redirect_uri=%7B%7BredirectUrl%7D%7D"
	-d "scope=full%20refresh_token"
https://login.salesforce.com{{site}}/services/oauth2/authorize

Postman Collection Item JSON

{
  "name": "Web Server Flow 1",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{url}}{{site}}/services/oauth2/authorize?response_type=code&client_id={{clientId}}&redirect_uri={{redirectUrl}}&scope=full refresh_token",
      "host": [
        "{{url}}{{site}}"
      ],
      "path": [
        "services",
        "oauth2",
        "authorize"
      ],
      "query": [
        {
          "key": "response_type",
          "value": "code"
        },
        {
          "key": "client_id",
          "value": "{{clientId}}"
        },
        {
          "key": "redirect_uri",
          "value": "{{redirectUrl}}"
        },
        {
          "key": "scope",
          "value": "full refresh_token"
        }
      ]
    }
  },
  "response": [
    {
      "name": "Successful Web Server Flow 1",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{url}}{{site}}/services/oauth2/authorize?response_type=code&client_id={{clientId}}&redirect_uri={{redirectUrl}}&scope=full refresh_token",
          "host": [
            "{{url}}{{site}}"
          ],
          "path": [
            "services",
            "oauth2",
            "authorize"
          ],
          "query": [
            {
              "key": "response_type",
              "value": "code"
            },
            {
              "key": "client_id",
              "value": "{{clientId}}"
            },
            {
              "key": "redirect_uri",
              "value": "{{redirectUrl}}"
            },
            {
              "key": "scope",
              "value": "full refresh_token"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "html",
      "header": [
        {
          "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": "Content-Security-Policy",
          "value": "upgrade-insecure-requests"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "must-revalidate,no-cache,no-store"
        },
        {
          "key": "Content-Type",
          "value": "text/html; charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Connection",
          "value": "close"
        }
      ],
      "cookie": [
      ],
      "body": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n\n<head>\n\t<meta HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\">\n\n\n\n\n\n\t<script>\n\t\tfunction redirectOnLoad() {\nif (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('<my-domain>?ec=302&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource%3D<token>'); }  else \nif (window.location.replace){ \nwindow.location.replace('<my-domain>?ec=302&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource%3D<token>');\n} else {\nwindow.location.href ='<my-domain>?ec=302&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource%3D<token>';\n} \n} \nredirectOnLoad();\n\t</script>\n\n</head>\n\n\n</html>\n\n\n\n\n\n<!-- Body events -->\n<script type=\"text/javascript\">\n\tfunction bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken=\"null\";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}\n</script>\n\n</body>\n\n</html>\n\n\n<!--\n...................................................................................................\n...................................................................................................\n...................................................................................................\n...................................................................................................\n-->"
    }
  ]
}