class GoogleOauth2Installed::Setup
To be used interactively. See ‘GoogleOauth2Installed.get_access_token`
Public Instance Methods
get_access_token()
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 8 def get_access_token checks.check_for_environment! auth_url = get_auth_url auth_code = ask_for_code auth_url token = get_token auth_code print_token token end
Private Instance Methods
ask_for_code(auth_url)
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 37 def ask_for_code(auth_url) puts "Please navigate to URL:\n\n\t%s\n\n" % auth_url print 'Then log in and paste the verification code: ' gets.chomp end
checks()
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 21 def checks Checks.new credentials end
client()
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 25 def client oauth2_info = credentials.values_at :oauth2_client_id, :oauth2_client_secret, :oauth2_urls @_client ||= OAuth2::Client.new(*oauth2_info) end
env_vars_for_token(token)
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 53 def env_vars_for_token(token) names = ["OAUTH2_ACCESS_TOKEN", "OAUTH2_REFRESH_TOKEN", "OAUTH2_EXPIRES_AT"] values = [token.token, token.refresh_token, token.expires_at].map { |v| "\"#{v}\"" } names.zip(values) end
get_auth_url()
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 30 def get_auth_url client.auth_code.authorize_url({ scope: scope, redirect_uri: redirect_uri, access_type: 'offline', approval_prompt: 'force', }) end
get_token(auth_code)
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 44 def get_token(auth_code) client.auth_code.get_token auth_code, redirect_uri: redirect_uri end
print_token(token)
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 48 def print_token(token) env_vars = env_vars_for_token(token).map { |a| a.join('=') }.join("\n") puts "\nRetrieved token from google. Put this in .env\n\n%s" % env_vars end
redirect_uri()
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 60 def redirect_uri credentials[:oauth2_redirect_uri] end
scope()
click to toggle source
# File lib/google-oauth2-installed/setup.rb, line 64 def scope credentials[:oauth2_scope] end