Classic ASP
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set rest = Server.CreateObject("Chilkat.Rest")
bTls = 1
bAutoReconnect = 1
success = rest.Connect("example.com",443,bTls,bAutoReconnect)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
Response.End
End If
' Configure Google service-account authentication. Load the service account JSON key and set the
' required OAuth scope(s).
set gAuth = Server.CreateObject("Chilkat.AuthGoogle")
set sbJsonKey = Server.CreateObject("Chilkat.StringBuilder")
bLoaded = sbJsonKey.LoadFile("qa_data/service_account.json")
If (bLoaded <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Failed to load the service account JSON key.") & "</pre>"
Response.End
End If
jsonKey = sbJsonKey.GetAsString()
If (sbJsonKey.LastMethodSuccess = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( sbJsonKey.LastErrorText) & "</pre>"
Response.End
End If
gAuth.JsonKey = jsonKey
' A space-delimited list of the requested permissions.
gAuth.Scope = "https://www.googleapis.com/auth/cloud-platform"
' Associate the provider so Chilkat supplies a Google bearer token on each request.
success = rest.SetAuthGoogle(gAuth)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
Response.End
End If
responseText = rest.FullRequestNoBody("GET","/storage/v1/b?project=my-project")
If (rest.LastMethodSuccess = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( responseText) & "</pre>"
%>
</body>
</html>