Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) S3 List Buckets using an STS Session TokenThis is an example showing how to use an STS session token in an Amazon AWS request. This example will list S3 buckets using a previously obtained session token.
IncludeFile "CkStringBuilder.pb" IncludeFile "CkXml.pb" IncludeFile "CkRest.pb" IncludeFile "CkAuthAws.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ; See Get AWS STS Session Token for sample code to get the session token XML. xmlToken.i = CkXml::ckCreate() If xmlToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkXml::ckLoadXmlFile(xmlToken,"qa_data/tokens/aws_session_token.xml") If success = 0 Debug CkXml::ckLastErrorText(xmlToken) CkXml::ckDispose(xmlToken) ProcedureReturn EndIf rest.i = CkRest::ckCreate() If rest.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to the Amazon AWS REST server. bTls.i = 1 port.i = 443 bAutoReconnect.i = 1 success = CkRest::ckConnect(rest,"s3.amazonaws.com",port,bTls,bAutoReconnect) ; Provide AWS credentials for the REST call. authAws.i = CkAuthAws::ckCreate() If authAws.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; The purpose of this example is to show how to use the temporary AccessKeyId, SecretAccessKey, and SessionToken. CkAuthAws::setCkAccessKey(authAws, CkXml::ckGetChildContent(xmlToken,"GetSessionTokenResult|Credentials|AccessKeyId")) CkAuthAws::setCkSecretKey(authAws, CkXml::ckGetChildContent(xmlToken,"GetSessionTokenResult|Credentials|SecretAccessKey")) CkAuthAws::setCkServiceName(authAws, "s3") success = CkRest::ckSetAuthAws(rest,authAws) CkRest::ckAddQueryParam(rest,"X-Amz-Security-Token",CkXml::ckGetChildContent(xmlToken,"GetSessionTokenResult|Credentials|SessionToken")) sbResponse.i = CkStringBuilder::ckCreate() If sbResponse.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkRest::ckFullRequestNoBodySb(rest,"GET","/",sbResponse) If success <> 1 Debug CkRest::ckLastErrorText(rest) CkXml::ckDispose(xmlToken) CkRest::ckDispose(rest) CkAuthAws::ckDispose(authAws) CkStringBuilder::ckDispose(sbResponse) ProcedureReturn EndIf statusCode.i = CkRest::ckResponseStatusCode(rest) Debug "Response status code = " + Str(statusCode) xml.i = CkXml::ckCreate() If xml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::ckLoadSb(xml,sbResponse,1) Debug CkXml::ckGetXml(xml) If statusCode <> 200 Debug "Failed. See error information in the XML." CkXml::ckDispose(xmlToken) CkRest::ckDispose(rest) CkAuthAws::ckDispose(authAws) CkStringBuilder::ckDispose(sbResponse) CkXml::ckDispose(xml) ProcedureReturn EndIf CkXml::ckDispose(xmlToken) CkRest::ckDispose(rest) CkAuthAws::ckDispose(authAws) CkStringBuilder::ckDispose(sbResponse) CkXml::ckDispose(xml) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.