Chilkat Online Tools

ERROR!

------------------- GenerateCode ----------------------
ImpliedContentType: application/x-www-form-urlencoded
---- begin chilkat script ----
// This example assumes the Chilkat API to have been previously unlocked.
// See {{-global_unlock:::Global Unlock Sample-}} for sample code.

new Http http;
ckbool success;

new HttpRequest req;
call req.AddParam("response_type","code_credentials");

new JsonObject jsonParam2;
call req.AddParam("client_id",jsonParam2.Emit());

new JsonObject jsonParam3;
call req.AddParam("redirect_uri",jsonParam3.Emit());
call req.AddParam("scope","");

call req.AddHeader("Auth-Verification-Type","email");
call req.AddHeader("Auth-Request-Type","user-registration");
call req.AddHeader("Authorization","Basic <base64Encoded identifier:otp>");

new HttpResponse resp;
req.HttpVerb = "POST";
req.ContentType = "application/x-www-form-urlencoded";
success = http.PostUrlEncoded("https://login.salesforce.com{{site}}/services/oauth2/authorize", req,resp);
if (success == ckfalse) {
println http.LastErrorText;
return;
}

println resp.StatusCode;
println resp.BodyStr;

---- end chilkat script ----

Go / Salesforce Platform APIs / Registration - Authorize

Back to Collection Items

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

    http := Http_Ref.html">Http_Ref.html">Http_Ref.html">Http_Ref.html">Http_Ref.html">Http_Ref.html">Http_Ref.html">chilkat.NewHttp()
    var success bool

    req := HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">HttpRequest_Ref.html">chilkat.NewHttpRequest()
    req.AddParam("response_type","code_credentials")

    jsonParam2 := JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">chilkat.NewJsonObject()
    req.AddParam("client_id",*jsonParam2.Emit())

    jsonParam3 := JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">JsonObject_Ref.html">chilkat.NewJsonObject()
    req.AddParam("redirect_uri",*jsonParam3.Emit())
    req.AddParam("scope","")

    req.AddHeader("Auth-Verification-Type","email")
    req.AddHeader("Auth-Request-Type","user-registration")
    req.AddHeader("Authorization","Basic <base64Encoded identifier:otp>")

    resp := HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">chilkat.NewHttpResponse()
    req.SetHttpVerb("POST")
    req.SetContentType("application/x-www-form-urlencoded")
ERROR: Assignment type mismatch.  ExpressionType=HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse_Ref.html">HttpResponse, atgType=ckbool

    if success == false {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        req.DisposeHttpRequest()
        jsonParam2.DisposeJsonObject()
        jsonParam3.DisposeJsonObject()
        resp.DisposeHttpResponse()
        return
    }

    fmt.Println(resp.StatusCode())
    fmt.Println(resp.BodyStr())

    http.DisposeHttp()
    req.DisposeHttpRequest()
    jsonParam2.DisposeJsonObject()
    jsonParam3.DisposeJsonObject()
    resp.DisposeHttpResponse()

Curl Command

curl -X POST
	-H "Auth-Request-Type: user-registration"
	-H "Auth-Verification-Type: email"
	-H "Authorization: Basic <base64Encoded identifier:otp>"
	--data-urlencode 'response_type=code_credentials'
	--data-urlencode 'client_id={{clientId}}'
	--data-urlencode 'redirect_uri={{redirectUrl}}'
	--data-urlencode 'scope='
https://login.salesforce.com{{site}}/services/oauth2/authorize

Postman Collection Item JSON

{
  "name": "Registration - Authorize",
  "request": {
    "auth": {
      "type": "noauth"
    },
    "method": "POST",
    "header": [
      {
        "key": "Auth-Request-Type",
        "value": "user-registration",
        "description": "Required for User Registration"
      },
      {
        "key": "Auth-Verification-Type",
        "value": "email",
        "description": "Must match init/registration, email or sms"
      },
      {
        "key": "Authorization",
        "value": "Basic <base64Encoded identifier:otp>",
        "description": "Base64 encoded <Identifier:OTP>"
      }
    ],
    "body": {
      "mode": "urlencoded",
      "urlencoded": [
        {
          "key": "response_type",
          "value": "code_credentials",
          "type": "text"
        },
        {
          "key": "client_id",
          "value": "{{clientId}}",
          "type": "text"
        },
        {
          "key": "redirect_uri",
          "value": "{{redirectUrl}}",
          "type": "text"
        },
        {
          "key": "scope",
          "value": "",
          "description": "Comma seperated list of scopes, optional",
          "type": "text"
        }
      ]
    },
    "url": {
      "raw": "{{url}}{{site}}/services/oauth2/authorize",
      "host": [
        "{{url}}{{site}}"
      ],
      "path": [
        "services",
        "oauth2",
        "authorize"
      ]
    },
    "description": "After you send your registration data to initialize, this request allows you to process that registration data, and as a part of this request you also verify the users email or sms number. The request itself is a authorization call for the Code and Credential flow. It includes 3 specific headers: `Auth-Request-Type` which is set to `user-registration`, `Auth-Verification-Type` which is set to email or sms, and an Authorization Basic header, which is the base 64 encoded result of `identifier:otp` where `identifier` is the value returned in your initialize registration call, and `otp` is the value sent to the end user via email or sms.\n\nThe response from this API is the Auth Code, which is then exchanged for the Access Token."
  },
  "response": [
  ]
}