Skip to content

Commit da7616d

Browse files
author
Tim Emiola
committed
Adds simple integration with googleauth
1 parent db23424 commit da7616d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

google-api-client.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
2626
s.add_runtime_dependency 'addressable', '~> 2.3'
2727
s.add_runtime_dependency 'signet', '~> 0.6'
2828
s.add_runtime_dependency 'faraday', '~> 0.9'
29+
s.add_runtime_dependency 'googleauth', '~> 0.1'
2930
s.add_runtime_dependency 'multi_json', '~> 1.10'
3031
s.add_runtime_dependency 'autoparse', "~> 0.3"
3132
s.add_runtime_dependency 'extlib', '~> 0.9'

lib/google/api_client.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ class APIClient
5454
# <li><code>:two_legged_oauth_1</code></li>
5555
# <li><code>:oauth_1</code></li>
5656
# <li><code>:oauth_2</code></li>
57+
# <li><code>:google_app_default</code></li>
5758
# </ul>
5859
# @option options [Boolean] :auto_refresh_token (true)
5960
# The setting that controls whether or not the api client attempts to
6061
# refresh authorization when a 401 is hit in #execute. If the token does
6162
# not support it, this option is ignored.
6263
# @option options [String] :application_name
6364
# The name of the application using the client.
65+
# @option options [String | Array | nil] :scope
66+
# The scope(s) used when using google application default credentials
6467
# @option options [String] :application_version
6568
# The version number of the application using the client.
6669
# @option options [String] :user_agent
@@ -114,6 +117,9 @@ def initialize(options={})
114117
# default authentication mechanisms.
115118
self.authorization =
116119
options.key?(:authorization) ? options[:authorization] : :oauth_2
120+
if !options['scope'].nil? and self.authorization.respond_to?(:scope=)
121+
self.authorization.scope = options['scope']
122+
end
117123
self.auto_refresh_token = options.fetch(:auto_refresh_token) { true }
118124
self.key = options[:key]
119125
self.user_ip = options[:user_ip]
@@ -174,6 +180,10 @@ def authorization=(new_authorization)
174180
:client_credential_secret => nil,
175181
:two_legged => true
176182
)
183+
when :google_app_default
184+
require 'googleauth'
185+
new_authorization = Google::Auth.get_application_default(nil)
186+
177187
when :oauth_2
178188
require 'signet/oauth_2/client'
179189
# NOTE: Do not rely on this default value, as it may change

0 commit comments

Comments
 (0)