Sample code for 30+ languages & platforms
Tcl

Example: Http.SetOAuthRsaKey method

Demonstrates the SetOAuthRsaKey method.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set pfx [new_CkPfx]

set success [CkPfx_LoadPfxFile $pfx "qa_data/pfx/MCD_Sandbox_chilkat_iccp_API_Keys/chilkat_iccp-sandbox.p12" "keystorepassword"]
if {$success == 0} then {
    puts [CkPfx_lastErrorText $pfx]
    delete_CkPfx $pfx
    exit
}

set privKey [new_CkPrivateKey]

set success [CkPfx_PrivateKeyAt $pfx 0 $privKey]
if {$success == 0} then {
    puts [CkPfx_lastErrorText $pfx]
    delete_CkPfx $pfx
    delete_CkPrivateKey $privKey
    exit
}

set http [new_CkHttp]

# Use OAuth1.0a authentication.
CkHttp_put_OAuth1 $http 1

# Use your own consumer key (this is not a valid consumer key)
CkHttp_put_OAuthConsumerKey $http "123abc"

CkHttp_put_OAuthSigMethod $http "RSA-SHA256"

set success [CkHttp_SetOAuthRsaKey $http $privKey]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkPfx $pfx
    delete_CkPrivateKey $privKey
    delete_CkHttp $http
    exit
}

# Tell Chilkat to automatically calculate and add the oauth_body_hash field when sending the request.
CkHttp_put_OAuthBodyHash $http 1

# Send this request to an endpoint at chilkatsoft.com.  The purpose of this example is to show
# how the OAuth1.0a Authorization header is computed and sent by Chilkat.
# The chilkatsoft.com site itself doesn't do OAuth1.  It's just ignoring the Authorization header.
set resp [new_CkHttpResponse]

set success [CkHttp_HttpStr $http "POST" "https://chilkatsoft.com/echo_request_body.asp" "<notUsed>123</notUsed>" "utf-8" "application/xml" $resp]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkPfx $pfx
    delete_CkPrivateKey $privKey
    delete_CkHttp $http
    delete_CkHttpResponse $resp
    exit
}

# Examine the request header we just sent..
puts [CkHttp_lastHeader $http]

# Sample output:

# POST /echo_request_body.asp HTTP/1.1
# Host: chilkatsoft.com
# Accept: */*
# Accept-Encoding: gzip
# Content-Type: application/xml
# Content-Length: 22
# Authorization: OAuth oauth_consumer_key="123abc", oauth_nonce="A2E91C3B53E0BD7FBF71F441336679E358DDCEEE", oauth_body_hash="a5kPTsDwUwmBjC0voNlAAvM6YoaRS5X7sTO49jl3/h8=", oauth_timestamp="1756324932", oauth_signature_method="RSA-SHA256", oauth_version="1.0", oauth_signature="*****"

delete_CkPfx $pfx
delete_CkPrivateKey $privKey
delete_CkHttp $http
delete_CkHttpResponse $resp