Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oRest
LOCAL nBTls
LOCAL nBAutoReconnect
LOCAL oOauth1
LOCAL nBUseQueryParams
LOCAL cResponseText
nSuccess := 0
oRest := CreateObject("Chilkat.Rest")
nBTls := 1
nBAutoReconnect := 1
nSuccess := oRest:Connect("example.com", 443, nBTls, nBAutoReconnect)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
RETURN
ENDIF
// Configure OAuth 1.0a request signing. Provide the consumer credentials and the access token
// credentials; Chilkat computes the OAuth signature for each request.
oOauth1 := CreateObject("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.
oOauth1:ConsumerKey := "CONSUMER_KEY"
oOauth1:ConsumerSecret := "CONSUMER_SECRET"
oOauth1:Token := "ACCESS_TOKEN"
oOauth1:TokenSecret := "ACCESS_TOKEN_SECRET"
oOauth1:SignatureMethod := "HMAC-SHA1"
// The 2nd argument selects whether OAuth parameters are placed in the query string (1) or the
// Authorization header (0).
nBUseQueryParams := 0
nSuccess := oRest:SetAuthOAuth1(oOauth1, nBUseQueryParams)
IF (nSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oOauth1:destroy()
RETURN
ENDIF
cResponseText := oRest:FullRequestNoBody("GET", "/api/resource")
IF (oRest:LastMethodSuccess == 0)
? oRest:LastErrorText
oRest:destroy()
oOauth1:destroy()
RETURN
ENDIF
? cResponseText
oRest:destroy()
oOauth1:destroy()