Google Sheets - Source
![]() |
---|
This repository contains the connector and configuration code only. The implementer is responsible to acquire the connection details such as username, password, certificate, etc. You might even need to sign a contract or agreement with the supplier before implementing this connector. Please contact the client’s application manager to coordinate the connector requirements. |
By using this connector you will have the ability to create one of the following items in Google GSuite:
$redirectUri = "http://localhost/oauth2callback"
$authUri = "https://accounts.google.com/o/oauth2/auth?client_id=$($ClientID)&scope=https://www.googleapis.com/auth/spreadsheets.readonly&response_type=code&redirect_uri=http://localhost/oauth2callback&access_type=offline&approval_prompt=force"
$HttpListener = New-Object System.Net.HttpListener
$HttpListener.Prefixes.Add(“http://+/oauth2callback/“)
$HttpListener.Start()
Start-Process $authUri
While ($HttpListener.IsListening) {
$HttpContext = $HttpListener.GetContext()
$HttpRequest = $HttpContext.Request
$RequestUrl = $HttpRequest.Url.OriginalString
#Authorization Code
$code = $HttpRequest.QueryString['code'];
Write-Host "Auth Code: $($code)";
#Request Refresh Token
$requestUri = "https://www.googleapis.com/oauth2/v4/token"
$body = @{
code=$code;
client_id=$clientId;
client_secret=$clientSecret;
redirect_uri=$redirectUri;
grant_type="authorization_code"; # Fixed value
};
$tokens = Invoke-RestMethod -Uri $requestUri -Method POST -Body $body;
Write-Host "Refresh Token: $($tokens.refresh_token)"
#Respond with Refresh Token
$HttpResponse = $HttpContext.Response
$HttpResponse.Headers.Add("Content-Type","text/plain")
$HttpResponse.StatusCode = 200
$ResponseBuffer = [System.Text.Encoding]::UTF8.GetBytes("Refresh Token: $($tokens.refresh_token)")
$HttpResponse.ContentLength64 = $ResponseBuffer.Length
$HttpResponse.OutputStream.Write($ResponseBuffer,0,$ResponseBuffer.Length)
$HttpResponse.Close()
#Stop Listener
$HttpListener.Stop()
}
### Manual Method
#### Getting the authorization code
With the authorization code, we can get the refresh token. We only need the refresh token.
1. To get the authorization code please use the URL below and replace the {replaceclientid} with the values from the OAuth client we created before.
2. Open the URL in a webbrowser of your choosing.
3. The browser will be redirected to the redirect URI. We will need to copy the code value out of the URL in the address bar, so we can obtain a refresh token in the next section.
Example
http://localhost/oauth2callback?code=4/QhUXhB********************z9jGKkhvac2&
The code would be 4/QhUXhB**z9jGKkhvac2&
```
Note: The claimed authorization code can be exchanged for a refreshtoken only once, otherwise you have to request a new authorization code as described above.
Add a new ‘Target System’ to HelloID and make sure to import all the necessary files.
Fill in the required fields on the ‘Configuration’ tab. See also, Setting up the Google API access
For more information about our HelloID PowerShell connectors, please refer to our general Documentation page
The official HelloID documentation can be found at: https://docs.helloid.com/