Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

MFC Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Bitfinex v2 REST
Bluzone
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
MedTunnel

MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter
UniPin
VoiceBase
Vonage
Walmart
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yousign
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(MFC) Zoom API - Create JWT to Authenticate API Requests

See more Zoom Examples

Creates a JWT for the Zoom API.

For more information, see https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#using-jwt

Chilkat C/C++ Library Downloads

MS Visual C/C++ Libs

See Also: Using MFC CString in Chilkat

#include <CkJwt.h>
#include <CkJsonObject.h>
#include <CkHttp.h>
#include <CkStringBuilder.h>

void ChilkatSample(void)
    {
    CkString strOut;

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

    // Use your API key and secret here...
    const char *apiKey = "o9rw6Gq0RnqlkfaSqtCMOA";
    const char *apiSecret = "UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR";

    // Create a JWT to authenticate Zoom API requests.
    CkJwt jwt;

    CkJsonObject jose;
    bool success = jose.UpdateString("alg","HS256");
    success = jose.UpdateString("typ","JWT");

    // Build claims to look like this:
    // {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363}
    CkJsonObject claims;
    success = claims.UpdateString("iss",apiKey);
    success = claims.UpdateNull("aud");

    // Set the timestamp of when the JWT was created to now.
    int curDateTime = jwt.GenNumericDate(0);
    success = claims.AddIntAt(-1,"iat",curDateTime);

    // Set the timestamp defining an expiration time (end time) for the token
    // to be now + 1 month(3600 * 24 * 30 seconds)
    int oneMonth = 3600 * 24 * 30;
    success = claims.AddIntAt(-1,"exp",curDateTime + oneMonth);

    // Produce the smallest possible JWT:
    jwt.put_AutoCompact(true);

    const char *strJwt = jwt.createJwt(jose.emit(),claims.emit(),apiSecret);

    strOut.append(strJwt);
    strOut.append("\r\n");

    // Let's test the JWT to by sending the following request:

    // curl --request GET \
    //   --url 'https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1' \
    //   --header 'authorization: Bearer { your_token }' \
    //   --header 'content-type: application/json

    CkHttp http;

    // Implements the following CURL command:

    // curl --request GET \
    //   --url 'https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1' \
    //   --header 'authorization: Bearer { your_token }' \
    //   --header 'content-type: application/json

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    http.SetRequestHeader("content-type","application/json");
    // Adds the "Authorization: Bearer { your_token }" header.
    http.put_AuthToken(strJwt);

    CkStringBuilder sbResponseBody;
    success = http.QuickGetSb("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1",sbResponseBody);
    if (success == false) {
        strOut.append(http.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    strOut.append("Response Body:");
    strOut.append("\r\n");
    strOut.append(jResp.emit());
    strOut.append("\r\n");

    int respStatusCode = http.get_LastStatus();
    strOut.append("Response Status Code = ");
    strOut.appendInt(respStatusCode);
    strOut.append("\r\n");
    if (respStatusCode >= 400) {
        strOut.append("Response Header:");
        strOut.append("\r\n");
        strOut.append(http.lastHeader());
        strOut.append("\r\n");
        strOut.append("Failed.");
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    // Sample output:

    // {
    //   "page_count": 1,
    //   "page_number": 1,
    //   "page_size": 30,
    //   "total_records": 1,
    //   "users": [
    //     {
    //       "id": "s8uAiMJiRmS_-eu1yOhKlg",
    //       "first_name": "Joe",
    //       "last_name": "Example",
    //       "email": "joe@example.com",
    //       "type": 1,
    //       "pmi": 5224934114,
    //       "timezone": "America/Chicago",
    //       "verified": 1,
    //       "created_at": "2021-07-30T11:56:37Z",
    //       "last_login_time": "2021-07-30T11:56:37Z",
    //       "language": "en-US",
    //       "phone_number": "",
    //       "status": "active",
    //       "role_id": "0"
    //     }
    //   ]
    // }

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

    const char *id = 0;
    const char *first_name = 0;
    const char *last_name = 0;
    const char *email = 0;
    int v_type;
    int pmi;
    const char *timezone = 0;
    int verified;
    const char *created_at = 0;
    const char *last_login_time = 0;
    const char *language = 0;
    const char *phone_number = 0;
    const char *status = 0;
    const char *role_id = 0;

    int page_count = jResp.IntOf("page_count");
    int page_number = jResp.IntOf("page_number");
    int page_size = jResp.IntOf("page_size");
    int total_records = jResp.IntOf("total_records");
    int i = 0;
    int count_i = jResp.SizeOfArray("users");
    while (i < count_i) {
        jResp.put_I(i);
        id = jResp.stringOf("users[i].id");
        first_name = jResp.stringOf("users[i].first_name");
        last_name = jResp.stringOf("users[i].last_name");
        email = jResp.stringOf("users[i].email");
        v_type = jResp.IntOf("users[i].type");
        pmi = jResp.IntOf("users[i].pmi");
        timezone = jResp.stringOf("users[i].timezone");
        verified = jResp.IntOf("users[i].verified");
        created_at = jResp.stringOf("users[i].created_at");
        last_login_time = jResp.stringOf("users[i].last_login_time");
        language = jResp.stringOf("users[i].language");
        phone_number = jResp.stringOf("users[i].phone_number");
        status = jResp.stringOf("users[i].status");
        role_id = jResp.stringOf("users[i].role_id");
        i = i + 1;
    }



    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

    }

 

© 2000-2022 Chilkat Software, Inc. All Rights Reserved.