Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(PowerBuilder) bitzlato.com whoami

Demonstrates sending a request to the bitzlato.com whoami endpoint using an ES256 JWT token for authentication.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Jwk
oleobject loo_EccKey
oleobject loo_Jwt
oleobject loo_Jose
oleobject loo_Claims
integer li_CurDateTime
string ls_Jwt_token
oleobject loo_Http
string ls_ResponseStr

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

//  Use the following ECC key loaded from JWK format.
loo_Jwk = create oleobject
li_rc = loo_Jwk.ConnectToNewObject("Chilkat_9_5_0.JsonObject")
if li_rc < 0 then
    destroy loo_Jwk
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Jwk.UpdateString("kty","EC")
li_Success = loo_Jwk.UpdateString("crv","P-256")
li_Success = loo_Jwk.UpdateString("x","...")
li_Success = loo_Jwk.UpdateString("y","...")
li_Success = loo_Jwk.UpdateString("d","...")

loo_EccKey = create oleobject
li_rc = loo_EccKey.ConnectToNewObject("Chilkat_9_5_0.PrivateKey")

li_Success = loo_EccKey.LoadJwk(loo_Jwk.Emit())
if li_Success = 0 then
    Write-Debug loo_EccKey.LastErrorText
    destroy loo_Jwk
    destroy loo_EccKey
    return
end if

loo_Jwt = create oleobject
li_rc = loo_Jwt.ConnectToNewObject("Chilkat_9_5_0.Jwt")

// Build the JOSE header
loo_Jose = create oleobject
li_rc = loo_Jose.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

li_Success = loo_Jose.AppendString("format","compact")
li_Success = loo_Jose.AppendString("alg","ES256")

// Now build the JWT claims (also known as the payload)

// Our JWT claims will contain members as shown here:

// 	{
// 	  "email":"your_email@example.com",
// 	  "aud":"usr",
// 	  "iat":"1588286154",
// 	  "jti":"555D9123"
// 	}

loo_Claims = create oleobject
li_rc = loo_Claims.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Claims.AppendString("jti","555D9123")
loo_Claims.AppendString("email","your_email@example.com")

// Set the timestamp of when the JWT was created to now minus 60 seconds
li_CurDateTime = loo_Jwt.GenNumericDate(-60)
li_Success = loo_Claims.AddIntAt(-1,"iat",li_CurDateTime)

// Set the "not process before" timestamp to now minus 60 seconds
li_Success = loo_Claims.AddIntAt(-1,"nbf",li_CurDateTime)

// Set the timestamp defining an expiration time (end time) for the token
// to be now + 1 hour (3600 seconds)
li_Success = loo_Claims.AddIntAt(-1,"exp",li_CurDateTime + 3600)

loo_Claims.AppendString("aud","usr")

// Produce the smallest possible JWT:
loo_Jwt.AutoCompact = 1

// Create the JWT token.  This is where the RSA signature is created.
ls_Jwt_token = loo_Jwt.CreateJwtPk(loo_Jose.Emit(),loo_Claims.Emit(),loo_EccKey)

Write-Debug ls_Jwt_token

// Send the HTTPS GET with the jwt_token used for Authorization.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")

loo_Http.AuthToken = ls_Jwt_token
ls_ResponseStr = loo_Http.QuickGetStr("https://bitzlato.com/api/auth/whoami")
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Jwk
    destroy loo_EccKey
    destroy loo_Jwt
    destroy loo_Jose
    destroy loo_Claims
    destroy loo_Http
    return
end if

Write-Debug "status code = " + string(loo_Http.LastStatus)
Write-Debug ls_ResponseStr


destroy loo_Jwk
destroy loo_EccKey
destroy loo_Jwt
destroy loo_Jose
destroy loo_Claims
destroy loo_Http

 

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