PowerBuilder
PowerBuilder
Configure AWS Signature Authentication for REST
See more REST Examples
Demonstrates Rest.SetAuthAws, which associates an AuthAws provider so Chilkat signs each request using AWS Signature Version 4. The provider supplies the access key, secret key, region, and service name.
Background. AWS requires each request to be signed with a signature derived from the secret key, region, service, and request contents. Configuring the provider lets Chilkat compute and attach the signature automatically.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_BAutoReconnect
oleobject loo_AuthAws
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 AWS Signature Version 4 request signing. Provide the access key, secret key, region,
// and service name.
loo_AuthAws = create oleobject
li_rc = loo_AuthAws.ConnectToNewObject("Chilkat.AuthAws")
// 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_AuthAws.AccessKey = "AWS_ACCESS_KEY"
loo_AuthAws.SecretKey = "AWS_SECRET_KEY"
loo_AuthAws.Region = "us-east-1"
loo_AuthAws.ServiceName = "s3"
// Associate the provider so Chilkat signs each request according to AWS requirements.
li_Success = loo_Rest.SetAuthAws(loo_AuthAws)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_AuthAws
return
end if
ls_ResponseText = loo_Rest.FullRequestNoBody("GET","/")
if loo_Rest.LastMethodSuccess = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_AuthAws
return
end if
Write-Debug ls_ResponseText
destroy loo_Rest
destroy loo_AuthAws