From 2c567fd720180db894b204dd518b50297712cbe3 Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Fri, 5 Oct 2012 12:07:42 +0300 Subject: [PATCH] Added the ability to create an authorization object from client secrets. --- CHANGELOG.md | 4 ++++ google-api-client.gemspec | 6 +++--- lib/google/api_client/client_secrets.rb | 27 +++++++++++++++++++++++++ lib/google/api_client/version.rb | 2 +- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 888c7dd61..93887fc37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.7 + +* Added the ability to convert client secrets to an authorization object + # 0.4.6 * Backwards compatibility for MultiJson diff --git a/google-api-client.gemspec b/google-api-client.gemspec index 1c3fb7eba..7b162ecee 100644 --- a/google-api-client.gemspec +++ b/google-api-client.gemspec @@ -2,16 +2,16 @@ Gem::Specification.new do |s| s.name = "google-api-client" - s.version = "0.4.6" + s.version = "0.4.7" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Bob Aman"] - s.date = "2012-08-30" + s.date = "2012-10-05" s.description = "The Google API Ruby Client makes it trivial to discover and access supported\nAPIs.\n" s.email = "bobaman@google.com" s.executables = ["google-api"] s.extra_rdoc_files = ["README.md"] - s.files = ["lib/compat", "lib/compat/multi_json.rb", "lib/google", "lib/google/api_client", "lib/google/api_client/batch.rb", "lib/google/api_client/client_secrets.rb", "lib/google/api_client/discovery", "lib/google/api_client/discovery/api.rb", "lib/google/api_client/discovery/media.rb", "lib/google/api_client/discovery/method.rb", "lib/google/api_client/discovery/resource.rb", "lib/google/api_client/discovery/schema.rb", "lib/google/api_client/discovery.rb", "lib/google/api_client/environment.rb", "lib/google/api_client/errors.rb", "lib/google/api_client/media.rb", "lib/google/api_client/reference.rb", "lib/google/api_client/result.rb", "lib/google/api_client/service_account.rb", "lib/google/api_client/version.rb", "lib/google/api_client.rb", "lib/google/inflection.rb", "spec/fixtures", "spec/fixtures/files", "spec/fixtures/files/sample.txt", "spec/google", "spec/google/api_client", "spec/google/api_client/batch_spec.rb", "spec/google/api_client/discovery_spec.rb", "spec/google/api_client/media_spec.rb", "spec/google/api_client/result_spec.rb", "spec/google/api_client/service_account_spec.rb", "spec/google/api_client_spec.rb", "spec/spec_helper.rb", "tasks/gem.rake", "tasks/git.rake", "tasks/metrics.rake", "tasks/spec.rake", "tasks/wiki.rake", "tasks/yard.rake", "CHANGELOG.md", "Gemfile", "Gemfile.lock", "LICENSE", "Rakefile", "README.md", "bin/google-api"] + s.files = ["lib/compat", "lib/compat/multi_json.rb", "lib/google", "lib/google/api_client", "lib/google/api_client/batch.rb", "lib/google/api_client/client_secrets.rb", "lib/google/api_client/discovery", "lib/google/api_client/discovery/api.rb", "lib/google/api_client/discovery/media.rb", "lib/google/api_client/discovery/method.rb", "lib/google/api_client/discovery/resource.rb", "lib/google/api_client/discovery/schema.rb", "lib/google/api_client/discovery.rb", "lib/google/api_client/environment.rb", "lib/google/api_client/errors.rb", "lib/google/api_client/media.rb", "lib/google/api_client/reference.rb", "lib/google/api_client/result.rb", "lib/google/api_client/service_account.rb", "lib/google/api_client/version.rb", "lib/google/api_client.rb", "lib/google/inflection.rb", "spec/fixtures", "spec/fixtures/files", "spec/fixtures/files/sample.txt", "spec/google", "spec/google/api_client", "spec/google/api_client/batch_spec.rb", "spec/google/api_client/discovery_spec.rb", "spec/google/api_client/media_spec.rb", "spec/google/api_client/result_spec.rb", "spec/google/api_client/service_account_spec.rb", "spec/google/api_client_spec.rb", "spec/spec_helper.rb", "tasks/gem.rake", "tasks/git.rake", "tasks/metrics.rake", "tasks/spec.rake", "tasks/wiki.rake", "tasks/yard.rake", "CHANGELOG.md", "Gemfile", "LICENSE", "Rakefile", "README.md", "bin/google-api"] s.homepage = "http://code.google.com/p/google-api-ruby-client/" s.rdoc_options = ["--main", "README.md"] s.require_paths = ["lib"] diff --git a/lib/google/api_client/client_secrets.rb b/lib/google/api_client/client_secrets.rb index 27b71087c..e70545289 100644 --- a/lib/google/api_client/client_secrets.rb +++ b/lib/google/api_client/client_secrets.rb @@ -101,6 +101,33 @@ module Google end }) end + + def to_authorization + gem 'signet', '~> 0.4.0' + require 'signet/oauth_2/client' + # NOTE: Do not rely on this default value, as it may change + new_authorization = Signet::OAuth2::Client.new + new_authorization.client_id = self.client_id + new_authorization.client_secret = self.client_secret + new_authorization.authorization_uri = ( + self.authorization_uri || + 'https://accounts.google.com/o/oauth2/auth' + ) + new_authorization.token_credential_uri = ( + self.token_credential_uri || + 'https://accounts.google.com/o/oauth2/token' + ) + new_authorization.redirect_uri = self.redirect_uris.first + + # These are supported, but unlikely. + new_authorization.access_token = self.access_token + new_authorization.refresh_token = self.refresh_token + new_authorization.id_token = self.id_token + new_authorization.expires_in = self.expires_in + new_authorization.issued_at = self.issued_at if self.issued_at + new_authorization.expires_at = self.expires_at if self.expires_at + return new_authorization + end end end end diff --git a/lib/google/api_client/version.rb b/lib/google/api_client/version.rb index 18c602143..8cf8acd43 100644 --- a/lib/google/api_client/version.rb +++ b/lib/google/api_client/version.rb @@ -22,7 +22,7 @@ if !defined?(::Google::APIClient::VERSION) module VERSION MAJOR = 0 MINOR = 4 - TINY = 6 + TINY = 7 STRING = [MAJOR, MINOR, TINY].join('.') end