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
Cloud Signature CSC
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
uncategorized

 

 

 

(PowerBuilder) Verify a Google JWT Using Google's Public Key

See more Google APIs Examples

Demonstrates how to verify a JWT that was signed using Google's RSA private key.

This example verifies the RSA signature. It also does the following:

  • Checks to see if the time constraints ("nbf" and "exp") are valid.
  • Recovers the original JOSE header.
  • Recovers the original claims JSON.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Http
oleobject loo_SbPubKeys
integer li_Success
string ls_Token
oleobject loo_Jwt
string ls_Header
oleobject loo_Json
string ls_Kid
oleobject loo_JsonPubKeys
oleobject loo_JsonKey
oleobject loo_PubKey

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_SbPubKeys = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbPubKeys.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://www.googleapis.com/oauth2/v3/certs",loo_SbPubKeys)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbPubKeys
    return
end if

Write-Debug loo_SbPubKeys.GetAsString()

// Here are the keys:

// {
//   "keys": [
//     {
//       "e": "AQAB",
//       "n": "4bAT6C6EeX8Dspje3FrAXw-nnhNk04e1RmNa4kjc0CHf6Pk7ryARlwA-6YilyPABqQfYHx60s8oSnxvUVprFfQ2-Q8aAZO7bPKSxnoGlcKERL2oLNA4Msvc89N9Y5ycThZUplf_QC19e6jyYXN6Nz-UnJSCLrtQY8tVhhVRs61j4A2N_p-enAi-r704Qi1-v-DKV4eVRkClKViploo8NyjUaT9L4vbBssPCjyimJzsWnEe1fED5c4LnHeArYzA_FEn3JJotqDIz9t2VnvZNTMhizHEX4VnORlEWMEfR8n4CEHQx7PcQUOmfqyw08gWeXQl1-uTjtIGaE-sRIv9u_vQ",
//       "kty": "RSA",
//       "use": "sig",
//       "alg": "RS256",
//       "kid": "2af90e87be140c20038898a6efa11283dab6031d"
//     },
//     {
//       "n": "nzGsrziOYrMVYMpvUZOwkKNiPWcOPTYRYlDSdRW4UpAHdWPbPlyqaaphYhoMB5DXrVxI3bdvm7DOlo-sHNnulmAFQa-7TsQMxrZCvVdAbyXGID9DZYEqf8mkCV1Ohv7WY5lDUqlybIk1OSHdK7-1et0QS8nn-5LojGg8FK4ssLf3mV1APpujl27D1bDhyRb1MGumXYElwlUms7F9p9OcSp5pTevXCLmXs9MJJk4o9E1zzPpQ9Ko0lH9l_UqFpA7vwQhnw0nbh73rXOX2TUDCUqL4ThKU5Z9Pd-eZCEOatKe0mJTpQ00XGACBME_6ojCdfNIJr84Y_IpGKvkAEksn9w",
//       "use": "sig",
//       "kid": "87bbe0815b064e6d449cac999f0e50e72a3e4374",
//       "e": "AQAB",
//       "alg": "RS256",
//       "kty": "RSA"
//     }
//   ]
// }

// -------------------------------------------------------------------------------------------
// Replace this with your actual token.
// This sample token contains a kid that does not match any of the above Google public keys.
// -------------------------------------------------------------------------------------------
ls_Token = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjQyZmY5MGQ3ZDM0OGM5NzM4MWE3YzExOWVmMWY1MzI0ZWEzZjViZWIifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJzdWIiOiIxMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExIiwiaWF0IjoxNjExMTE1MTQzLCJleHAiOjE2MTEyMDE1NDMsImF1ZCI6IjQyOTc1NzExNTE0ODg0OSJ9.pLem5i0bx3M7lJYj7jKv2Nq7c07X5YpZz-x1uM5RniW-v4LsX-lKIVvOq2x3-WoPqkzLXJfP0kG0dx1uD2q1NfFQK60YwKH4FnFtB6INnUP1dRVpP9_pTTKyAE28I3s5Tay4PbPdrCl7ZLCIJzCfpCW1TiWeVoPjp5HgZKTBHdP_sEkN_yO5dQerQXAkFJkV3kNgF9jI3ayT-KPqOIH6GVoWXjHFDyA2EYgJPEFRo5WSe6XycJ85p5duwT-OoBcb_kJZG9PxYd91eHlPCzp8vGxzIb2dVROCBxyM8e8W0cd9v15hfmpg9R-eG9vCM5y63ZLChZLFeHFx0Pd7hvAqfKg"

loo_Jwt = create oleobject
// Use "Chilkat_9_5_0.Jwt" for versions of Chilkat < 10.0.0
li_rc = loo_Jwt.ConnectToNewObject("Chilkat.Jwt")

ls_Header = loo_Jwt.GetHeader(ls_Token)

Write-Debug ls_Header

// Sample header:
// {"alg":"RS256","kid":"87bbe0815b064e6d449cac999f0e50e72a3e4374"}

// Load the public key matching the "kid" into a Chilkat public key object, then verify..

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.Load(ls_Header)
ls_Kid = loo_Json.StringOf("kid")

Write-Debug "kid = " + ls_Kid

loo_JsonPubKeys = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonPubKeys.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonPubKeys.LoadSb(loo_SbPubKeys)

loo_JsonKey = loo_JsonPubKeys.FindRecord("keys","kid",ls_Kid,1)
if loo_JsonPubKeys.LastMethodSuccess = 0 then
    Write-Debug "Did not find a matching public key based on the kid."
    destroy loo_Http
    destroy loo_SbPubKeys
    destroy loo_Jwt
    destroy loo_Json
    destroy loo_JsonPubKeys
    return
end if

Write-Debug loo_JsonKey.Emit()

// Load the matching public key into a Chilkat public key object.
loo_PubKey = create oleobject
// Use "Chilkat_9_5_0.PublicKey" for versions of Chilkat < 10.0.0
li_rc = loo_PubKey.ConnectToNewObject("Chilkat.PublicKey")

li_Success = loo_PubKey.LoadFromString(loo_JsonKey.Emit())
destroy loo_JsonKey
if li_Success = 0 then
    Write-Debug loo_PubKey.LastErrorText
    destroy loo_Http
    destroy loo_SbPubKeys
    destroy loo_Jwt
    destroy loo_Json
    destroy loo_JsonPubKeys
    destroy loo_PubKey
    return
end if

// ----------------------------------------------------------------------------------------
// Now we can validate the JWT using Google's public key as shown in this example:
// (Except we use the public key obtained as shown above instead of a public key loaded from a PEM file.
// 
// See Verify JWT Using an RSA Public Key


destroy loo_Http
destroy loo_SbPubKeys
destroy loo_Jwt
destroy loo_Json
destroy loo_JsonPubKeys
destroy loo_PubKey

 

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