Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL loOauth1
LOCAL lnBUseQueryParams
LOCAL lcResponseText

lnSuccess = 0

loRest = CreateObject('Chilkat.Rest')
lnBTls = 1
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("example.com",443,lnBTls,lnBAutoReconnect)
IF (lnSuccess = 0) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

*  Configure OAuth 1.0a request signing.  Provide the consumer credentials and the access token
*  credentials; Chilkat computes the OAuth signature for each request.
loOauth1 = 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.
loOauth1.ConsumerKey = "CONSUMER_KEY"
loOauth1.ConsumerSecret = "CONSUMER_SECRET"
loOauth1.Token = "ACCESS_TOKEN"
loOauth1.TokenSecret = "ACCESS_TOKEN_SECRET"
loOauth1.SignatureMethod = "HMAC-SHA1"

*  The 2nd argument selects whether OAuth parameters are placed in the query string (1) or the
*  Authorization header (0).
lnBUseQueryParams = 0
lnSuccess = loRest.SetAuthOAuth1(loOauth1,lnBUseQueryParams)
IF (lnSuccess = 0) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth1
    CANCEL
ENDIF

lcResponseText = loRest.FullRequestNoBody("GET","/api/resource")
IF (loRest.LastMethodSuccess = 0) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth1
    CANCEL
ENDIF

? lcResponseText

RELEASE loRest
RELEASE loOauth1