0
votes

I need to authorize both of these scopes for my Google App Script:

https://www.googleapis.com/auth/drive

https://www.googleapis.com/auth/spreadsheets

How do I authorize both? I current have the follow to authorize the first one:

OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
APPLICATION_NAME = 'My App'
CLIENT_SECRETS_PATH = 'lib/google_auth.json'
CREDENTIALS_PATH = File.join(Dir.home, '.credentials',
                             "script-ruby-my-app.yaml")
SCOPE = 'https://www.googleapis.com/auth/drive'

def authorize
  FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))

  client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
  token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)
  authorizer = Google::Auth::UserAuthorizer.new(
    client_id, SCOPE, token_store)
  user_id = 'default'
  credentials = authorizer.get_credentials(user_id)
  if credentials.nil?
    url = authorizer.get_authorization_url(
      base_url: OOB_URI)
    puts "Open the following URL in the browser and enter the " +
         "resulting code after authorization"
    puts url
    code = gets
    credentials = authorizer.get_and_store_credentials_from_code(
      user_id: user_id, code: code, base_url: OOB_URI)
  end
  credentials
end
2

2 Answers

1
votes

Found it. SCOPE can be an array, so multiple services can be authorized with a single call.

0
votes

@Batman answered his own question, but I thought an example could be helpful for those having the same issue.

Scopes can be an array, like so...

"oauthScopes": ["https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.readonly",
"https://www.google.com/calendar/feeds",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/spreadsheets"]