Sample code for 30+ languages & platforms
PowerBuilder

Configure OAuth 1.0a Authentication for REST

See more REST Examples

Demonstrates Rest.SetAuthOAuth1, which associates an OAuth1 provider so Chilkat computes the OAuth 1.0/1.0a signature for each request. The second argument selects whether OAuth parameters are placed in the query string or the Authorization header.

Background. OAuth 1.0a signs each request using the consumer key/secret and the access token/secret. Chilkat generates the nonce, timestamp, and signature automatically for every request sent through the object.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
oleobject loo_Oauth1
integer li_BUseQueryParams
string ls_ResponseText

li_Success = 0

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_BTls = 1
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("example.com",443,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    return
end if

//  Configure OAuth 1.0a request signing.  Provide the consumer credentials and the access token
//  credentials; Chilkat computes the OAuth signature for each request.
loo_Oauth1 = create oleobject
li_rc = loo_Oauth1.ConnectToNewObject("Chilkat.OAuth1")

//  Normally you would not hard-code secrets in source.  You should instead obtain them from an
//  interactive prompt, environment variable, or a secrets vault.
loo_Oauth1.ConsumerKey = "CONSUMER_KEY"
loo_Oauth1.ConsumerSecret = "CONSUMER_SECRET"
loo_Oauth1.Token = "ACCESS_TOKEN"
loo_Oauth1.TokenSecret = "ACCESS_TOKEN_SECRET"
loo_Oauth1.SignatureMethod = "HMAC-SHA1"

//  The 2nd argument selects whether OAuth parameters are placed in the query string (1) or the
//  Authorization header (0).
li_BUseQueryParams = 0
li_Success = loo_Rest.SetAuthOAuth1(loo_Oauth1,li_BUseQueryParams)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth1
    return
end if

ls_ResponseText = loo_Rest.FullRequestNoBody("GET","/api/resource")
if loo_Rest.LastMethodSuccess = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth1
    return
end if

Write-Debug ls_ResponseText


destroy loo_Rest
destroy loo_Oauth1