Merge pull request #200 from tbetbetbe/google-api-enable-google-auth

Adds simple integration with googleauth
This commit is contained in:
Steve Bazyl 2015-03-10 10:50:11 -07:00
commit 847b48357c
2 changed files with 11 additions and 0 deletions

View File

@ -26,6 +26,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'addressable', '~> 2.3' s.add_runtime_dependency 'addressable', '~> 2.3'
s.add_runtime_dependency 'signet', '~> 0.6' s.add_runtime_dependency 'signet', '~> 0.6'
s.add_runtime_dependency 'faraday', '~> 0.9' s.add_runtime_dependency 'faraday', '~> 0.9'
s.add_runtime_dependency 'googleauth', '~> 0.1'
s.add_runtime_dependency 'multi_json', '~> 1.10' s.add_runtime_dependency 'multi_json', '~> 1.10'
s.add_runtime_dependency 'autoparse', "~> 0.3" s.add_runtime_dependency 'autoparse', "~> 0.3"
s.add_runtime_dependency 'extlib', '~> 0.9' s.add_runtime_dependency 'extlib', '~> 0.9'

View File

@ -54,6 +54,7 @@ module Google
# <li><code>:two_legged_oauth_1</code></li> # <li><code>:two_legged_oauth_1</code></li>
# <li><code>:oauth_1</code></li> # <li><code>:oauth_1</code></li>
# <li><code>:oauth_2</code></li> # <li><code>:oauth_2</code></li>
# <li><code>:google_app_default</code></li>
# </ul> # </ul>
# @option options [Boolean] :auto_refresh_token (true) # @option options [Boolean] :auto_refresh_token (true)
# The setting that controls whether or not the api client attempts to # The setting that controls whether or not the api client attempts to
@ -61,6 +62,8 @@ module Google
# not support it, this option is ignored. # not support it, this option is ignored.
# @option options [String] :application_name # @option options [String] :application_name
# The name of the application using the client. # The name of the application using the client.
# @option options [String | Array | nil] :scope
# The scope(s) used when using google application default credentials
# @option options [String] :application_version # @option options [String] :application_version
# The version number of the application using the client. # The version number of the application using the client.
# @option options [String] :user_agent # @option options [String] :user_agent
@ -114,6 +117,9 @@ module Google
# default authentication mechanisms. # default authentication mechanisms.
self.authorization = self.authorization =
options.key?(:authorization) ? options[:authorization] : :oauth_2 options.key?(:authorization) ? options[:authorization] : :oauth_2
if !options['scope'].nil? and self.authorization.respond_to?(:scope=)
self.authorization.scope = options['scope']
end
self.auto_refresh_token = options.fetch(:auto_refresh_token) { true } self.auto_refresh_token = options.fetch(:auto_refresh_token) { true }
self.key = options[:key] self.key = options[:key]
self.user_ip = options[:user_ip] self.user_ip = options[:user_ip]
@ -174,6 +180,10 @@ module Google
:client_credential_secret => nil, :client_credential_secret => nil,
:two_legged => true :two_legged => true
) )
when :google_app_default
require 'googleauth'
new_authorization = Google::Auth.get_application_default(nil)
when :oauth_2 when :oauth_2
require 'signet/oauth_2/client' require 'signet/oauth_2/client'
# NOTE: Do not rely on this default value, as it may change # NOTE: Do not rely on this default value, as it may change