AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
$oRest = ObjCreate("Chilkat.Rest")
Local $bTls = True
Local $bAutoReconnect = True
$bSuccess = $oRest.Connect("example.com",443,$bTls,$bAutoReconnect)
If ($bSuccess = False) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
; Configure Google service-account authentication. Load the service account JSON key and set the
; required OAuth scope(s).
$oGAuth = ObjCreate("Chilkat.AuthGoogle")
$oSbJsonKey = ObjCreate("Chilkat.StringBuilder")
Local $bLoaded = $oSbJsonKey.LoadFile("qa_data/service_account.json")
If ($bLoaded <> True) Then
ConsoleWrite("Failed to load the service account JSON key." & @CRLF)
Exit
EndIf
Local $sJsonKey = $oSbJsonKey.GetAsString()
If ($oSbJsonKey.LastMethodSuccess = False) Then
ConsoleWrite($oSbJsonKey.LastErrorText & @CRLF)
Exit
EndIf
$oGAuth.JsonKey = $sJsonKey
; A space-delimited list of the requested permissions.
$oGAuth.Scope = "https://www.googleapis.com/auth/cloud-platform"
; Associate the provider so Chilkat supplies a Google bearer token on each request.
$bSuccess = $oRest.SetAuthGoogle($oGAuth)
If ($bSuccess = False) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
Local $sResponseText = $oRest.FullRequestNoBody("GET","/storage/v1/b?project=my-project")
If ($oRest.LastMethodSuccess = False) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite($sResponseText & @CRLF)