Visual FoxPro
Visual FoxPro
Configure Google Service Account Authentication for REST
See more REST Examples
Demonstrates Rest.SetAuthGoogle, which associates an AuthGoogle provider so Chilkat supplies a Google OAuth 2.0 bearer token on each request. The provider is configured with a service account JSON key and the required OAuth scope.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. The AuthGoogle provider performs a service-account (server-to-server) OAuth flow. For interactive, browser-based user consent, the OAuth2 provider is used instead.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnBAutoReconnect
LOCAL loGAuth
LOCAL loSbJsonKey
LOCAL lnBLoaded
LOCAL lcJsonKey
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 Google service-account authentication. Load the service account JSON key and set the
* required OAuth scope(s).
loGAuth = CreateObject('Chilkat.AuthGoogle')
loSbJsonKey = CreateObject('Chilkat.StringBuilder')
lnBLoaded = loSbJsonKey.LoadFile("qa_data/service_account.json")
IF (lnBLoaded <> 1) THEN
? "Failed to load the service account JSON key."
RELEASE loRest
RELEASE loGAuth
RELEASE loSbJsonKey
CANCEL
ENDIF
lcJsonKey = loSbJsonKey.GetAsString()
IF (loSbJsonKey.LastMethodSuccess = 0) THEN
? loSbJsonKey.LastErrorText
RELEASE loRest
RELEASE loGAuth
RELEASE loSbJsonKey
CANCEL
ENDIF
loGAuth.JsonKey = lcJsonKey
* A space-delimited list of the requested permissions.
loGAuth.Scope = "https://www.googleapis.com/auth/cloud-platform"
* Associate the provider so Chilkat supplies a Google bearer token on each request.
lnSuccess = loRest.SetAuthGoogle(loGAuth)
IF (lnSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loGAuth
RELEASE loSbJsonKey
CANCEL
ENDIF
lcResponseText = loRest.FullRequestNoBody("GET","/storage/v1/b?project=my-project")
IF (loRest.LastMethodSuccess = 0) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loGAuth
RELEASE loSbJsonKey
CANCEL
ENDIF
? lcResponseText
RELEASE loRest
RELEASE loGAuth
RELEASE loSbJsonKey