DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Boolean iBAutoReconnect
Variant vOauth1
Handle hoOauth1
Boolean iBUseQueryParams
String sResponseText
String sTemp1
Boolean bTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Move True To iBTls
Move True To iBAutoReconnect
Get ComConnect Of hoRest "example.com" 443 iBTls iBAutoReconnect To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Configure OAuth 1.0a request signing. Provide the consumer credentials and the access token
// credentials; Chilkat computes the OAuth signature for each request.
Get Create (RefClass(cComChilkatOAuth1)) To hoOauth1
If (Not(IsComObjectCreated(hoOauth1))) Begin
Send CreateComObject of hoOauth1
End
// Normally you would not hard-code secrets in source. You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
Set ComConsumerKey Of hoOauth1 To "CONSUMER_KEY"
Set ComConsumerSecret Of hoOauth1 To "CONSUMER_SECRET"
Set ComToken Of hoOauth1 To "ACCESS_TOKEN"
Set ComTokenSecret Of hoOauth1 To "ACCESS_TOKEN_SECRET"
Set ComSignatureMethod Of hoOauth1 To "HMAC-SHA1"
// The 2nd argument selects whether OAuth parameters are placed in the query string (True) or the
// Authorization header (False).
Move False To iBUseQueryParams
Get pvComObject of hoOauth1 to vOauth1
Get ComSetAuthOAuth1 Of hoRest vOauth1 iBUseQueryParams To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComFullRequestNoBody Of hoRest "GET" "/api/resource" To sResponseText
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Showln sResponseText
End_Procedure