Chilkat Online Tools

C / Salesforce Platform APIs / ID Token

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *id;
    BOOL asserted_user;
    const char *user_id;
    const char *organization_id;
    const char *username;
    const char *nick_name;
    const char *display_name;
    const char *email;
    BOOL email_verified;
    const char *first_name;
    const char *last_name;
    const char *timezone;
    const char *Picture;
    const char *Thumbnail;
    const char *addr_street;
    const char *addr_city;
    const char *addr_state;
    const char *addr_country;
    const char *addr_zip;
    const char *mobile_phone;
    BOOL mobile_phone_verified;
    BOOL is_lightning_login_user;
    const char *Created_date;
    const char *Body;
    const char *Enterprise;
    const char *Metadata;
    const char *Partner;
    const char *v_Rest;
    const char *Sobjects;
    const char *Search;
    const char *Query;
    const char *Recent;
    const char *Tooling_soap;
    const char *Tooling_rest;
    const char *Profile;
    const char *Feeds;
    const char *Groups;
    const char *Users;
    const char *Feed_items;
    const char *Feed_elements;
    const char *Custom_domain;
    BOOL active;
    const char *user_type;
    const char *language;
    const char *locale;
    int utcOffset;
    const char *last_modified_date;
    BOOL is_app_installed;

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

    http = CkHttp_Create();

    CkHttp_SetRequestHeader(http,"Content-Type","application/json");

    sbResponseBody = CkStringBuilder_Create();
    success = CkHttp_QuickGetSb(http,"https://domain.com/id/{{_orgId}}/{{_userId}}",sbResponseBody);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttp_getLastStatus(http);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttp_lastHeader(http));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "id": "https://login.salesforce.com/id/00D.../005...",
    //   "asserted_user": true,
    //   "user_id": "005...",
    //   "organization_id": "00D...",
    //   "username": "<username>",
    //   "nick_name": "<nickname>",
    //   "display_name": "<display_name>",
    //   "email": "<email>",
    //   "email_verified": true,
    //   "first_name": "<firstname>",
    //   "last_name": "<lastname>",
    //   "timezone": "Europe/Paris",
    //   "photos": {
    //     "picture": "https://<my_domain>/profilephoto/005/F",
    //     "thumbnail": "https://<my_domain>/profilephoto/005/T"
    //   },
    //   "addr_street": null,
    //   "addr_city": null,
    //   "addr_state": null,
    //   "addr_country": "FR",
    //   "addr_zip": null,
    //   "mobile_phone": null,
    //   "mobile_phone_verified": false,
    //   "is_lightning_login_user": false,
    //   "status": {
    //     "created_date": null,
    //     "body": null
    //   },
    //   "urls": {
    //     "enterprise": "https://<my_domain>/services/Soap/c/{version}/00D...",
    //     "metadata": "https://<my_domain>/services/Soap/m/{version}/00D...",
    //     "partner": "https://<my_domain>/services/Soap/u/{version}/00D...",
    //     "rest": "https://<my_domain>/services/data/v{version}/",
    //     "sobjects": "https://<my_domain>/services/data/v{version}/sobjects/",
    //     "search": "https://<my_domain>/services/data/v{version}/search/",
    //     "query": "https://<my_domain>/services/data/v{version}/query/",
    //     "recent": "https://<my_domain>/services/data/v{version}/recent/",
    //     "tooling_soap": "https://<my_domain>/services/Soap/T/{version}/00D...",
    //     "tooling_rest": "https://<my_domain>/services/data/v{version}/tooling/",
    //     "profile": "https://<my_domain>/0052o00000DOJ1PAAX",
    //     "feeds": "https://<my_domain>/services/data/v{version}/chatter/feeds",
    //     "groups": "https://<my_domain>/services/data/v{version}/chatter/groups",
    //     "users": "https://<my_domain>/services/data/v{version}/chatter/users",
    //     "feed_items": "https://<my_domain>/services/data/v{version}/chatter/feed-items",
    //     "feed_elements": "https://<my_domain>/services/data/v{version}/chatter/feed-elements",
    //     "custom_domain": "https://<my_domain>"
    //   },
    //   "active": true,
    //   "user_type": "STANDARD",
    //   "language": "en_US",
    //   "locale": "fr_FR_EURO",
    //   "utcOffset": 3600000,
    //   "last_modified_date": "<date_time>",
    //   "is_app_installed": true
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    id = CkJsonObject_stringOf(jResp,"id");
    asserted_user = CkJsonObject_BoolOf(jResp,"asserted_user");
    user_id = CkJsonObject_stringOf(jResp,"user_id");
    organization_id = CkJsonObject_stringOf(jResp,"organization_id");
    username = CkJsonObject_stringOf(jResp,"username");
    nick_name = CkJsonObject_stringOf(jResp,"nick_name");
    display_name = CkJsonObject_stringOf(jResp,"display_name");
    email = CkJsonObject_stringOf(jResp,"email");
    email_verified = CkJsonObject_BoolOf(jResp,"email_verified");
    first_name = CkJsonObject_stringOf(jResp,"first_name");
    last_name = CkJsonObject_stringOf(jResp,"last_name");
    timezone = CkJsonObject_stringOf(jResp,"timezone");
    Picture = CkJsonObject_stringOf(jResp,"photos.picture");
    Thumbnail = CkJsonObject_stringOf(jResp,"photos.thumbnail");
    addr_street = CkJsonObject_stringOf(jResp,"addr_street");
    addr_city = CkJsonObject_stringOf(jResp,"addr_city");
    addr_state = CkJsonObject_stringOf(jResp,"addr_state");
    addr_country = CkJsonObject_stringOf(jResp,"addr_country");
    addr_zip = CkJsonObject_stringOf(jResp,"addr_zip");
    mobile_phone = CkJsonObject_stringOf(jResp,"mobile_phone");
    mobile_phone_verified = CkJsonObject_BoolOf(jResp,"mobile_phone_verified");
    is_lightning_login_user = CkJsonObject_BoolOf(jResp,"is_lightning_login_user");
    Created_date = CkJsonObject_stringOf(jResp,"status.created_date");
    Body = CkJsonObject_stringOf(jResp,"status.body");
    Enterprise = CkJsonObject_stringOf(jResp,"urls.enterprise");
    Metadata = CkJsonObject_stringOf(jResp,"urls.metadata");
    Partner = CkJsonObject_stringOf(jResp,"urls.partner");
    v_Rest = CkJsonObject_stringOf(jResp,"urls.rest");
    Sobjects = CkJsonObject_stringOf(jResp,"urls.sobjects");
    Search = CkJsonObject_stringOf(jResp,"urls.search");
    Query = CkJsonObject_stringOf(jResp,"urls.query");
    Recent = CkJsonObject_stringOf(jResp,"urls.recent");
    Tooling_soap = CkJsonObject_stringOf(jResp,"urls.tooling_soap");
    Tooling_rest = CkJsonObject_stringOf(jResp,"urls.tooling_rest");
    Profile = CkJsonObject_stringOf(jResp,"urls.profile");
    Feeds = CkJsonObject_stringOf(jResp,"urls.feeds");
    Groups = CkJsonObject_stringOf(jResp,"urls.groups");
    Users = CkJsonObject_stringOf(jResp,"urls.users");
    Feed_items = CkJsonObject_stringOf(jResp,"urls.feed_items");
    Feed_elements = CkJsonObject_stringOf(jResp,"urls.feed_elements");
    Custom_domain = CkJsonObject_stringOf(jResp,"urls.custom_domain");
    active = CkJsonObject_BoolOf(jResp,"active");
    user_type = CkJsonObject_stringOf(jResp,"user_type");
    language = CkJsonObject_stringOf(jResp,"language");
    locale = CkJsonObject_stringOf(jResp,"locale");
    utcOffset = CkJsonObject_IntOf(jResp,"utcOffset");
    last_modified_date = CkJsonObject_stringOf(jResp,"last_modified_date");
    is_app_installed = CkJsonObject_BoolOf(jResp,"is_app_installed");


    CkHttp_Dispose(http);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl -X GET
	-H "Content-Type: application/json"
https://domain.com/id/{{_orgId}}/{{_userId}}

Postman Collection Item JSON

{
  "name": "ID Token",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "type": "text",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{_endpoint}}/id/{{_orgId}}/{{_userId}}",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "id",
        "{{_orgId}}",
        "{{_userId}}"
      ]
    }
  },
  "response": [
    {
      "name": "Successful ID Token",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{_endpoint}}/id/{{_orgId}}/{{_userId}}",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "id",
            "{{_orgId}}",
            "{{_userId}}"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 16 Nov 2023 15:56:09 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": "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    \"id\": \"https://login.salesforce.com/id/00D.../005...\",\n    \"asserted_user\": true,\n    \"user_id\": \"005...\",\n    \"organization_id\": \"00D...\",\n    \"username\": \"<username>\",\n    \"nick_name\": \"<nickname>\",\n    \"display_name\": \"<display_name>\",\n    \"email\": \"<email>\",\n    \"email_verified\": true,\n    \"first_name\": \"<firstname>\",\n    \"last_name\": \"<lastname>\",\n    \"timezone\": \"Europe/Paris\",\n    \"photos\": {\n        \"picture\": \"https://<my_domain>/profilephoto/005/F\",\n        \"thumbnail\": \"https://<my_domain>/profilephoto/005/T\"\n    },\n    \"addr_street\": null,\n    \"addr_city\": null,\n    \"addr_state\": null,\n    \"addr_country\": \"FR\",\n    \"addr_zip\": null,\n    \"mobile_phone\": null,\n    \"mobile_phone_verified\": false,\n    \"is_lightning_login_user\": false,\n    \"status\": {\n        \"created_date\": null,\n        \"body\": null\n    },\n    \"urls\": {\n        \"enterprise\": \"https://<my_domain>/services/Soap/c/{version}/00D...\",\n        \"metadata\": \"https://<my_domain>/services/Soap/m/{version}/00D...\",\n        \"partner\": \"https://<my_domain>/services/Soap/u/{version}/00D...\",\n        \"rest\": \"https://<my_domain>/services/data/v{version}/\",\n        \"sobjects\": \"https://<my_domain>/services/data/v{version}/sobjects/\",\n        \"search\": \"https://<my_domain>/services/data/v{version}/search/\",\n        \"query\": \"https://<my_domain>/services/data/v{version}/query/\",\n        \"recent\": \"https://<my_domain>/services/data/v{version}/recent/\",\n        \"tooling_soap\": \"https://<my_domain>/services/Soap/T/{version}/00D...\",\n        \"tooling_rest\": \"https://<my_domain>/services/data/v{version}/tooling/\",\n        \"profile\": \"https://<my_domain>/0052o00000DOJ1PAAX\",\n        \"feeds\": \"https://<my_domain>/services/data/v{version}/chatter/feeds\",\n        \"groups\": \"https://<my_domain>/services/data/v{version}/chatter/groups\",\n        \"users\": \"https://<my_domain>/services/data/v{version}/chatter/users\",\n        \"feed_items\": \"https://<my_domain>/services/data/v{version}/chatter/feed-items\",\n        \"feed_elements\": \"https://<my_domain>/services/data/v{version}/chatter/feed-elements\",\n        \"custom_domain\": \"https://<my_domain>\"\n    },\n    \"active\": true,\n    \"user_type\": \"STANDARD\",\n    \"language\": \"en_US\",\n    \"locale\": \"fr_FR_EURO\",\n    \"utcOffset\": 3600000,\n    \"last_modified_date\": \"<date_time>\",\n    \"is_app_installed\": true\n}"
    }
  ]
}