Chilkat Online Tools

lianja / Salesforce Platform APIs / User Agent Flow

Back to Collection Items

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loHttp = createobject("CkHttp")

loQueryParams = createobject("CkJsonObject")
loQueryParams.UpdateString("response_type","token")
loQueryParams.UpdateString("client_id","{{clientId}}")
loQueryParams.UpdateString("redirect_uri","{{redirectUrl}}")
loQueryParams.UpdateString("display","touch")
loQueryParams.UpdateString("login_hint","")
loQueryParams.UpdateString("nonce","awesome")

loResp = loHttp.QuickRequestParams("GET","https://login.salesforce.com{{site}}/services/oauth2/authorize",loQueryParams)
if (loHttp.LastMethodSuccess = .F.) then
    ? loHttp.LastErrorText
    release loHttp
    release loQueryParams
    return
endif

? str(loResp.StatusCode)
? loResp.BodyStr
release loResp


release loHttp
release loQueryParams

Curl Command

curl -G -d "response_type=token"
	-d "client_id=%7B%7BclientId%7D%7D"
	-d "redirect_uri=%7B%7BredirectUrl%7D%7D"
	-d "display=touch"
	-d "login_hint="
	-d "nonce=awesome"
https://login.salesforce.com{{site}}/services/oauth2/authorize

Postman Collection Item JSON

{
  "name": "User Agent Flow",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "const jsonData = pm.response.json();",
          "const id = jsonData.id.split('/');",
          "",
          "const context = pm.environment.name ? pm.environment : pm.collectionVariables;",
          "context.set(\"_accessToken\", jsonData.access_token);",
          "context.set(\"_refreshToken\", jsonData.refresh_token);",
          "context.set(\"_endpoint\", jsonData.instance_url);",
          "context.set(\"_userId\", id.pop());",
          "context.set(\"_orgId\", id.pop());"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{url}}{{site}}/services/oauth2/authorize?response_type=token&client_id={{clientId}}&redirect_uri={{redirectUrl}}&display=touch&login_hint&nonce=awesome",
      "host": [
        "{{url}}{{site}}"
      ],
      "path": [
        "services",
        "oauth2",
        "authorize"
      ],
      "query": [
        {
          "key": "response_type",
          "value": "token"
        },
        {
          "key": "client_id",
          "value": "{{clientId}}"
        },
        {
          "key": "redirect_uri",
          "value": "{{redirectUrl}}"
        },
        {
          "key": "display",
          "value": "touch"
        },
        {
          "key": "login_hint",
          "value": null
        },
        {
          "key": "nonce",
          "value": "awesome"
        }
      ]
    }
  },
  "response": [
    {
      "name": "Successful User Agent Flow",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{url}}{{site}}/services/oauth2/authorize?response_type=token&client_id={{clientId}}&redirect_uri={{redirectUrl}}&display=touch&login_hint&nonce=awesome",
          "host": [
            "{{url}}{{site}}"
          ],
          "path": [
            "services",
            "oauth2",
            "authorize"
          ],
          "query": [
            {
              "key": "response_type",
              "value": "token"
            },
            {
              "key": "client_id",
              "value": "{{clientId}}"
            },
            {
              "key": "redirect_uri",
              "value": "{{redirectUrl}}"
            },
            {
              "key": "display",
              "value": "touch"
            },
            {
              "key": "login_hint",
              "value": null
            },
            {
              "key": "nonce",
              "value": "awesome"
            }
          ]
        }
      },
      "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": "\n\n\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n    <head>\n        <meta HTTP-EQUIV=\"PRAGMA\" CONTENT=\"NO-CACHE\">\n        <script>\nfunction redirectOnLoad() {\nif (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('<my-domain>?ec=302&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource%3D<token>%26display%3Dtouch&display=touch'); }  else \nif (window.location.replace){ \nwindow.location.replace('<my-domain>>?ec=302&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource%3D<token>%26display%3Dtouch&display=touch');\n} else {\nwindow.location.href ='<my-domain>>?ec=302&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource%3D<token>%26display%3Dtouch&display=touch';\n} \n} \nredirectOnLoad();\n</script>\n    </head>\n</html>\n<!-- Body events -->\n<script type=\"text/javascript\">function bodyOnLoad(){if(window.PreferenceBits){window.PreferenceBits.prototype.csrfToken=\"null\";};}function bodyOnBeforeUnload(){}function bodyOnFocus(){}function bodyOnUnload(){}</script>\n</body>\n</html>\n<!--\n...................................................................................................\n...................................................................................................\n...................................................................................................\n...................................................................................................\n-->\n"
    }
  ]
}