theodi/odi-metrics-tasks

View on GitHub
bin/oauth

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

# If we ever need to generate a new access / refresh token, this script will do it for us

require "rubygems"
require "google/api_client"
require "google_drive"
require 'dotenv'
Dotenv.load

# Authorizes with OAuth and gets an access token.
client = Google::APIClient.new
auth = client.authorization
auth.client_id = ENV['GAPPS_CLIENT_ID']
auth.client_secret = ENV['GAPPS_CLIENT_SECRET']
auth.scope =
    "https://docs.google.com/feeds/" +
    "https://www.googleapis.com/auth/drive " +
    "https://spreadsheets.google.com/feeds/"
auth.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
print("1. Open this page:\n%s\n\n" % auth.authorization_uri)
print("2. Enter the authorization code shown in the page: ")
auth.code = $stdin.gets.chomp
auth.fetch_access_token!
access_token = auth.access_token

puts "Here be your access token: #{access_token}"
puts "Here be your refresh token: #{auth.refresh_token}"