Skip to content

Commit

Permalink
Merge pull request googleapis#200 from tbetbetbe/google-api-enable-go…
Browse files Browse the repository at this point in the history
…ogle-auth

Adds simple integration with googleauth
  • Loading branch information
sqrrrl committed Mar 10, 2015
2 parents db23424 + da7616d commit 847b483
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions google-api-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'addressable', '~> 2.3'
s.add_runtime_dependency 'signet', '~> 0.6'
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 'autoparse', "~> 0.3"
s.add_runtime_dependency 'extlib', '~> 0.9'
Expand Down
10 changes: 10 additions & 0 deletions lib/google/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ class APIClient
# <li><code>:two_legged_oauth_1</code></li>
# <li><code>:oauth_1</code></li>
# <li><code>:oauth_2</code></li>
# <li><code>:google_app_default</code></li>
# </ul>
# @option options [Boolean] :auto_refresh_token (true)
# The setting that controls whether or not the api client attempts to
# refresh authorization when a 401 is hit in #execute. If the token does
# not support it, this option is ignored.
# @option options [String] :application_name
# 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
# The version number of the application using the client.
# @option options [String] :user_agent
Expand Down Expand Up @@ -114,6 +117,9 @@ def initialize(options={})
# default authentication mechanisms.
self.authorization =
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.key = options[:key]
self.user_ip = options[:user_ip]
Expand Down Expand Up @@ -174,6 +180,10 @@ def authorization=(new_authorization)
:client_credential_secret => nil,
:two_legged => true
)
when :google_app_default
require 'googleauth'
new_authorization = Google::Auth.get_application_default(nil)

when :oauth_2
require 'signet/oauth_2/client'
# NOTE: Do not rely on this default value, as it may change
Expand Down

0 comments on commit 847b483

Please sign in to comment.