googleauth 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/CONTRIBUTING.md +51 -10
- data/README.md +3 -1
- data/googleauth.gemspec +4 -2
- data/lib/googleauth.rb +7 -6
- data/lib/googleauth/credentials_loader.rb +6 -6
- data/lib/googleauth/service_account.rb +2 -2
- data/lib/googleauth/user_refresh.rb +2 -2
- data/lib/googleauth/version.rb +1 -1
- data/spec/googleauth/compute_engine_spec.rb +3 -3
- data/spec/googleauth/get_application_default_spec.rb +12 -0
- data/spec/googleauth/service_account_spec.rb +2 -2
- data/spec/googleauth/signet_spec.rb +5 -5
- data/spec/googleauth/user_refresh_spec.rb +2 -2
- data/spec/spec_helper.rb +7 -0
- metadata +35 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0585a45f95885a97c727eef608c4ed257676f1a7
|
4
|
+
data.tar.gz: e7caca78b8212296986474b7d1c6eab7f3a4666b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac7fc0cc2b64b76aa51ff9e0f2c26c4432624ebc8b1c8ac7b47022448c7d946f3071e858cbc20c6671309cd966ae2e59a46f2855c6b78f5a435607637859070e
|
7
|
+
data.tar.gz: 362554243c77276cf8c9f560117cd8627971c957af4ab1bac886eafec19482437bcca6fb034ac84609aa09321629f8cccb1ba26693f81881c1ea24ebc364e58e
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## Contributor License Agreements
|
4
4
|
|
5
|
-
We'd love to accept your sample apps and patches! Before we can take them, we
|
5
|
+
We'd love to accept your sample apps and patches! Before we can take them, we
|
6
6
|
have to jump a couple of legal hurdles.
|
7
7
|
|
8
8
|
Please fill out either the individual or corporate Contributor License Agreement
|
@@ -19,14 +19,55 @@ Follow either of the two links above to access the appropriate CLA and
|
|
19
19
|
instructions for how to sign and return it. Once we receive it, we'll be able to
|
20
20
|
accept your pull requests.
|
21
21
|
|
22
|
-
##
|
22
|
+
## Issue reporting
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
1. Submit a pull request.
|
24
|
+
* Check that the issue has not already been reported.
|
25
|
+
* Check that the issue has not already been fixed in the latest code
|
26
|
+
(a.k.a. `master`).
|
27
|
+
* Be clear, concise and precise in your description of the problem.
|
28
|
+
* Open an issue with a descriptive title and a summary in grammatically correct,
|
29
|
+
complete sentences.
|
30
|
+
* Include any relevant code to the issue summary.
|
32
31
|
|
32
|
+
## Pull requests
|
33
|
+
|
34
|
+
* Read [how to properly contribute to open source projects on Github][2].
|
35
|
+
* Fork the project.
|
36
|
+
* Use a topic/feature branch to easily amend a pull request later, if necessary.
|
37
|
+
* Write [good commit messages][3].
|
38
|
+
* Use the same coding conventions as the rest of the project.
|
39
|
+
* Commit and push until you are happy with your contribution.
|
40
|
+
* Make sure to add tests for it. This is important so I don't break it
|
41
|
+
in a future version unintentionally.
|
42
|
+
* Add an entry to the [Changelog](CHANGELOG.md) accordingly. See [changelog entry format](#changelog-entry-format).
|
43
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to
|
44
|
+
have your own version, or is otherwise necessary, that is fine, but please
|
45
|
+
isolate to its own commit so I can cherry-pick around it.
|
46
|
+
* Make sure the test suite is passing and the code you wrote doesn't produce
|
47
|
+
RuboCop offenses.
|
48
|
+
* [Squash related commits together][5].
|
49
|
+
* Open a [pull request][4] that relates to *only* one subject with a clear title
|
50
|
+
and description in grammatically correct, complete sentences.
|
51
|
+
|
52
|
+
### Changelog entry format
|
53
|
+
|
54
|
+
Here are a few examples:
|
55
|
+
|
56
|
+
```
|
57
|
+
* makes the scope parameter's optional in all APIs. (@tbetbetbe[])
|
58
|
+
* [#14](https://github.com/google/google-auth-library-ruby/issues/14): ADC Support for JWT Service Tokens. ([@tbetbetbe][])
|
59
|
+
```
|
60
|
+
|
61
|
+
* Mark it up in [Markdown syntax][6].
|
62
|
+
* The entry line should start with `* ` (an asterisk and a space).
|
63
|
+
* If the change has a related GitHub issue (e.g. a bug fix for a reported issue), put a link to the issue as `[#123](https://github.com/google/google-auth-library-ruby/issues/11): `.
|
64
|
+
* Describe the brief of the change. The sentence should end with a punctuation.
|
65
|
+
* At the end of the entry, add an implicit link to your GitHub user page as `([@username][])`.
|
66
|
+
* If this is your first contribution to google-auth-library-ruby project, add a link definition for the implicit link to the bottom of the changelog as `[@username]: https://github.com/username`.
|
67
|
+
|
68
|
+
[1]: https://github.com/google/google-auth-ruby-library/issues
|
69
|
+
[2]: http://gun.io/blog/how-to-github-fork-branch-and-pull-request
|
70
|
+
[3]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
71
|
+
[4]: https://help.github.com/articles/using-pull-requests
|
72
|
+
[5]: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
|
73
|
+
[6]: http://daringfireball.net/projects/markdown/syntax
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Google Auth Library for Ruby
|
1
|
+
# Google Auth Library for Ruby
|
2
2
|
|
3
3
|
<dl>
|
4
4
|
<dt>Homepage</dt><dd><a href="http://www.github.com/google/google-auth-library-ruby">http://www.github.com/google/google-auth-library-ruby</a></dd>
|
@@ -7,7 +7,9 @@
|
|
7
7
|
<dt>License</dt><dd>Apache 2.0</dd>
|
8
8
|
</dl>
|
9
9
|
|
10
|
+
[![Gem Version](https://badge.fury.io/rb/googleauth.svg)](http://badge.fury.io/rb/googleauth)
|
10
11
|
[![Build Status](https://secure.travis-ci.org/google/google-auth-library-ruby.png)](http://travis-ci.org/google/google-auth-library-ruby)
|
12
|
+
[![Coverage Status](https://coveralls.io/repos/google/google-auth-library-ruby/badge.png)](https://coveralls.io/r/google/google-auth-library-ruby)
|
11
13
|
[![Dependency Status](https://gemnasium.com/google/google-auth-library-ruby.png)](https://gemnasium.com/google/google-auth-library-ruby)
|
12
14
|
|
13
15
|
## Description
|
data/googleauth.gemspec
CHANGED
@@ -27,13 +27,15 @@ Gem::Specification.new do |s|
|
|
27
27
|
|
28
28
|
s.add_dependency 'faraday', '~> 0.9'
|
29
29
|
s.add_dependency 'logging', '~> 1.8'
|
30
|
-
s.add_dependency 'jwt', '~> 1.
|
30
|
+
s.add_dependency 'jwt', '~> 1.4.1'
|
31
31
|
s.add_dependency 'memoist', '~> 0.11.0'
|
32
32
|
s.add_dependency 'multi_json', '1.11.0'
|
33
33
|
s.add_dependency 'signet', '~> 0.6.0'
|
34
34
|
|
35
35
|
s.add_development_dependency 'bundler', '~> 1.7'
|
36
|
+
s.add_development_dependency 'simplecov', '~> 0.9.2'
|
37
|
+
s.add_development_dependency 'coveralls', '~> 0.7.11'
|
36
38
|
s.add_development_dependency 'rake', '~> 10.0'
|
37
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
39
|
+
s.add_development_dependency 'rubocop', '~> 0.29.1'
|
38
40
|
s.add_development_dependency 'rspec', '~> 3.0'
|
39
41
|
end
|
data/lib/googleauth.rb
CHANGED
@@ -52,9 +52,9 @@ END
|
|
52
52
|
|
53
53
|
# override CredentialsLoader#make_creds to use the class determined by
|
54
54
|
# loading the json.
|
55
|
-
def self.make_creds(
|
55
|
+
def self.make_creds(json_key_io, scope = nil)
|
56
56
|
json_key, clz = determine_creds_class(json_key_io)
|
57
|
-
clz.new(
|
57
|
+
clz.new(StringIO.new(MultiJson.dump(json_key)), scope)
|
58
58
|
end
|
59
59
|
|
60
60
|
# Reads the input json and determines which creds class to use.
|
@@ -75,12 +75,13 @@ END
|
|
75
75
|
# Google APIs. Application Default Credentials are described in detail
|
76
76
|
# at http://goo.gl/IUuyuX.
|
77
77
|
#
|
78
|
-
# If supplied, scope is used to create the credentials instance, when it
|
79
|
-
#
|
78
|
+
# If supplied, scope is used to create the credentials instance, when it can
|
79
|
+
# be applied. E.g, on google compute engine and for user credentials the
|
80
|
+
# scope is ignored.
|
80
81
|
#
|
81
|
-
# @param scope [string|array] the scope(s) to access
|
82
|
+
# @param scope [string|array|nil] the scope(s) to access
|
82
83
|
# @param options [hash] allows override of the connection being used
|
83
|
-
def get_application_default(scope, options = {})
|
84
|
+
def get_application_default(scope = nil, options = {})
|
84
85
|
creds = DefaultCredentials.from_env(scope)
|
85
86
|
return creds unless creds.nil?
|
86
87
|
creds = DefaultCredentials.from_well_known_path(scope)
|
@@ -61,13 +61,13 @@ module Google
|
|
61
61
|
# Creates an instance from the path specified in an environment
|
62
62
|
# variable.
|
63
63
|
#
|
64
|
-
# @param scope [string|array] the scope(s) to access
|
65
|
-
def from_env(scope)
|
64
|
+
# @param scope [string|array|nil] the scope(s) to access
|
65
|
+
def from_env(scope = nil)
|
66
66
|
return nil unless ENV.key?(ENV_VAR)
|
67
67
|
path = ENV[ENV_VAR]
|
68
68
|
fail 'file #{path} does not exist' unless File.exist?(path)
|
69
69
|
File.open(path) do |f|
|
70
|
-
return make_creds(
|
70
|
+
return make_creds(f, scope)
|
71
71
|
end
|
72
72
|
rescue StandardError => e
|
73
73
|
raise "#{NOT_FOUND_ERROR}: #{e}"
|
@@ -75,15 +75,15 @@ module Google
|
|
75
75
|
|
76
76
|
# Creates an instance from a well known path.
|
77
77
|
#
|
78
|
-
# @param scope [string|array] the scope(s) to access
|
79
|
-
def from_well_known_path(scope)
|
78
|
+
# @param scope [string|array|nil] the scope(s) to access
|
79
|
+
def from_well_known_path(scope = nil)
|
80
80
|
home_var, base = windows? ? 'APPDATA' : 'HOME', WELL_KNOWN_PATH
|
81
81
|
root = ENV[home_var].nil? ? '' : ENV[home_var]
|
82
82
|
base = File.join('.config', base) unless windows?
|
83
83
|
path = File.join(root, base)
|
84
84
|
return nil unless File.exist?(path)
|
85
85
|
File.open(path) do |f|
|
86
|
-
return make_creds(
|
86
|
+
return make_creds(f, scope)
|
87
87
|
end
|
88
88
|
rescue StandardError => e
|
89
89
|
raise "#{WELL_KNOWN_ERROR}: #{e}"
|
@@ -57,9 +57,9 @@ module Google
|
|
57
57
|
|
58
58
|
# Initializes a ServiceAccountCredentials.
|
59
59
|
#
|
60
|
-
# @param scope [string|array] the scope(s) to access
|
61
60
|
# @param json_key_io [IO] an IO from which the JSON key can be read
|
62
|
-
|
61
|
+
# @param scope [string|array|nil] the scope(s) to access
|
62
|
+
def initialize(json_key_io, scope = nil)
|
63
63
|
private_key, client_email = self.class.read_json_key(json_key_io)
|
64
64
|
super(token_credential_uri: TOKEN_CRED_URI,
|
65
65
|
audience: TOKEN_CRED_URI,
|
@@ -61,9 +61,9 @@ module Google
|
|
61
61
|
|
62
62
|
# Initializes a UserRefreshCredentials.
|
63
63
|
#
|
64
|
-
# @param scope [string|array] the scope(s) to access
|
65
64
|
# @param json_key_io [IO] an IO from which the JSON key can be read
|
66
|
-
|
65
|
+
# @param scope [string|array|nil] the scope(s) to access
|
66
|
+
def initialize(json_key_io, scope = nil)
|
67
67
|
user_creds = self.class.read_json_key(json_key_io)
|
68
68
|
super(token_credential_uri: TOKEN_CRED_URI,
|
69
69
|
client_id: user_creds['client_id'],
|
data/lib/googleauth/version.rb
CHANGED
@@ -51,9 +51,9 @@ describe Google::Auth::GCECredentials do
|
|
51
51
|
headers = env[:request_headers]
|
52
52
|
expect(headers['Metadata-Flavor']).to eq('Google')
|
53
53
|
build_json_response(
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
'access_token' => access_token,
|
55
|
+
'token_type' => 'Bearer',
|
56
|
+
'expires_in' => 3600)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -104,6 +104,18 @@ describe '#get_application_default' do
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
it 'succeeds with default file without a scope' do
|
108
|
+
ENV.delete(@var_name) unless ENV[@var_name].nil?
|
109
|
+
Dir.mktmpdir do |dir|
|
110
|
+
key_path = File.join(dir, '.config',
|
111
|
+
CredentialsLoader::WELL_KNOWN_PATH)
|
112
|
+
FileUtils.mkdir_p(File.dirname(key_path))
|
113
|
+
File.write(key_path, cred_json_text)
|
114
|
+
ENV['HOME'] = dir
|
115
|
+
expect(Google::Auth.get_application_default).to_not be_nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
107
119
|
it 'succeeds without default file or env if on compute engine' do
|
108
120
|
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
109
121
|
stub.get('/') do |_env|
|
@@ -47,8 +47,8 @@ describe Google::Auth::ServiceAccountCredentials do
|
|
47
47
|
before(:example) do
|
48
48
|
@key = OpenSSL::PKey::RSA.new(2048)
|
49
49
|
@client = ServiceAccountCredentials.new(
|
50
|
-
|
51
|
-
|
50
|
+
StringIO.new(cred_json_text),
|
51
|
+
'https://www.googleapis.com/auth/userinfo.profile')
|
52
52
|
end
|
53
53
|
|
54
54
|
def make_auth_stubs(opts = {})
|
@@ -41,11 +41,11 @@ describe Signet::OAuth2::Client do
|
|
41
41
|
before(:example) do
|
42
42
|
@key = OpenSSL::PKey::RSA.new(2048)
|
43
43
|
@client = Signet::OAuth2::Client.new(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
|
45
|
+
scope: 'https://www.googleapis.com/auth/userinfo.profile',
|
46
|
+
issuer: 'app@example.com',
|
47
|
+
audience: 'https://accounts.google.com/o/oauth2/token',
|
48
|
+
signing_key: @key
|
49
49
|
)
|
50
50
|
end
|
51
51
|
|
@@ -47,8 +47,8 @@ describe Google::Auth::UserRefreshCredentials do
|
|
47
47
|
before(:example) do
|
48
48
|
@key = OpenSSL::PKey::RSA.new(2048)
|
49
49
|
@client = UserRefreshCredentials.new(
|
50
|
-
|
51
|
-
|
50
|
+
StringIO.new(cred_json_text),
|
51
|
+
'https://www.googleapis.com/auth/userinfo.profile')
|
52
52
|
end
|
53
53
|
|
54
54
|
def make_auth_stubs(opts = {})
|
data/spec/spec_helper.rb
CHANGED
@@ -35,6 +35,13 @@ $LOAD_PATH.unshift(spec_dir)
|
|
35
35
|
$LOAD_PATH.unshift(lib_dir)
|
36
36
|
$LOAD_PATH.uniq!
|
37
37
|
|
38
|
+
# set up coverage
|
39
|
+
require 'simplecov'
|
40
|
+
require 'coveralls'
|
41
|
+
|
42
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
43
|
+
SimpleCov.start
|
44
|
+
|
38
45
|
require 'faraday'
|
39
46
|
require 'rspec'
|
40
47
|
require 'logging'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googleauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Emiola
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.4.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.4.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: memoist
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.7'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.9.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.9.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: coveralls
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.7.11
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.7.11
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: rake
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +156,14 @@ dependencies:
|
|
128
156
|
requirements:
|
129
157
|
- - "~>"
|
130
158
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
159
|
+
version: 0.29.1
|
132
160
|
type: :development
|
133
161
|
prerelease: false
|
134
162
|
version_requirements: !ruby/object:Gem::Requirement
|
135
163
|
requirements:
|
136
164
|
- - "~>"
|
137
165
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.
|
166
|
+
version: 0.29.1
|
139
167
|
- !ruby/object:Gem::Dependency
|
140
168
|
name: rspec
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +192,7 @@ files:
|
|
164
192
|
- ".rubocop.yml"
|
165
193
|
- ".rubocop_todo.yml"
|
166
194
|
- ".travis.yml"
|
195
|
+
- CHANGELOG.md
|
167
196
|
- CONTRIBUTING.md
|
168
197
|
- COPYING
|
169
198
|
- Gemfile
|