ADF_BigQuery icon indicating copy to clipboard operation
ADF_BigQuery copied to clipboard

Request access to Google drive option

Open dg-hub opened this issue 2 years ago • 0 comments

Hi @AnalyticJeremy !

Thanks for your great work!

In order to Enable the "Request access to Google drive" option in the Google BigQuery Linked Service as described here

An additional scope needs to be added to Authentication Request in 01 Get Code URL.ps1

The additional scope is: https://www.googleapis.com/auth/drive

It is required when creating external tables to Google Sheets. I have implemented this by adding the following....

# A PowerShell script for getting an OAuth code URL from Google
# (This is Step 1 of a two-step process)
# written by Jeremy Peach (AnalyticJeremy)
# full documentation:  https://github.com/AnalyticJeremy/ADF_BigQuery


# Before running this script, you need to set these three values.  They can be
# obtained from the GCP console.

$driveScopeEnabled = Read-Host " -- Include access to Google Drive y/n? [n]"

$clientId = ""
$clientSecret = ""
$redirectUrl = "http://127.0.0.1/"


# This is the access scope we will be requesting
$scope = "https://www.googleapis.com/auth/bigquery"
$driveScope = "https://www.googleapis.com/auth/drive"


# Build the URL for Google's OAuth service
$authUrl = "https://accounts.google.com/o/oauth2/v2/auth"
$authUrl += "?client_id=" + $clientId
$authUrl += "&redirect_uri=" + [uri]::EscapeDataString($redirectUrl) 
$authUrl += "&scope=" + [uri]::EscapeDataString($scope)
if($driveScopeEnabled.ToLower() -eq "y") {
   $authUrl += "+" + [uri]::EscapeDataString($driveScope)
}

$authUrl += "&access_type=offline&include_granted_scopes=true&response_type=code&prompt=consent"

Write-Host "`n`n$("*" * 80) `n"
Write-Host "Open the follwing URL in your web browser:`n"
Write-Host "`t$authUrl`n"
Write-Host "Log into Google and grant consent to the application.  After clicking allow, you will be redirected to a URL."
Write-Host "Copy the URL to which you are redirected and proceed to Step 2."
Write-Host "`n$("*" * 80) `n`n"

dg-hub avatar Feb 28 '22 01:02 dg-hub