googleauth 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -1
- data/.travis.yml +3 -1
- data/CHANGELOG.md +13 -6
- data/Gemfile +6 -6
- data/README.md +17 -11
- data/googleauth.gemspec +2 -1
- data/lib/googleauth.rb +6 -6
- data/lib/googleauth/client_id.rb +10 -10
- data/lib/googleauth/compute_engine.rb +18 -14
- data/lib/googleauth/credentials_loader.rb +14 -13
- data/lib/googleauth/iam.rb +4 -4
- data/lib/googleauth/scope_util.rb +2 -2
- data/lib/googleauth/service_account.rb +7 -7
- data/lib/googleauth/signet.rb +22 -1
- data/lib/googleauth/stores/redis_token_store.rb +7 -7
- data/lib/googleauth/token_store.rb +3 -3
- data/lib/googleauth/user_authorizer.rb +36 -24
- data/lib/googleauth/user_refresh.rb +16 -13
- data/lib/googleauth/version.rb +1 -1
- data/lib/googleauth/web_user_authorizer.rb +30 -25
- data/spec/googleauth/apply_auth_examples.rb +5 -4
- data/spec/googleauth/client_id_spec.rb +6 -3
- data/spec/googleauth/compute_engine_spec.rb +19 -5
- data/spec/googleauth/get_application_default_spec.rb +10 -13
- data/spec/googleauth/scope_util_spec.rb +4 -2
- data/spec/googleauth/service_account_spec.rb +7 -4
- data/spec/googleauth/signet_spec.rb +4 -3
- data/spec/googleauth/stores/file_token_store_spec.rb +1 -2
- data/spec/googleauth/user_authorizer_spec.rb +22 -12
- data/spec/googleauth/user_refresh_spec.rb +21 -3
- data/spec/googleauth/web_user_authorizer_spec.rb +15 -8
- metadata +5 -7
- data/.rubocop_todo.yml +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7166e05e50e9d66f0fbbe0ed95674c008772078
|
4
|
+
data.tar.gz: ac765a872c1302acc55ff76acff1adb3c421402a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e379500990afa645e680fef25c180d6476042bbeeda083d02cd442d98a5cc3c1ce9f47bcab8ac4463841b51a5aa8603051da1e30884cd4dc207e5c75404acde
|
7
|
+
data.tar.gz: 22aa2ecb920bd44334d5dfbfc906b3a736a56943c5a8d90d43ad7762648542884ee9392e31acfb45ec44233fae34ca0f957d963f6cba554dba7e86df4b07c7da
|
data/.rubocop.yml
CHANGED
@@ -1 +1,26 @@
|
|
1
|
-
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- "spec/**/*"
|
4
|
+
|
5
|
+
Metrics/AbcSize:
|
6
|
+
Max: 25
|
7
|
+
Metrics/BlockLength:
|
8
|
+
Exclude:
|
9
|
+
- "googleauth.gemspec"
|
10
|
+
Metrics/CyclomaticComplexity:
|
11
|
+
Max: 8
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 20
|
14
|
+
Metrics/ClassLength:
|
15
|
+
Enabled: false
|
16
|
+
Style/IndentHeredoc:
|
17
|
+
Enabled: false
|
18
|
+
Style/FormatString:
|
19
|
+
Enabled: false
|
20
|
+
Style/GuardClause:
|
21
|
+
Enabled: false
|
22
|
+
Style/PercentLiteralDelimiters: # Contradicting rule
|
23
|
+
Enabled: false
|
24
|
+
Style/SymbolArray: # Undefined syntax in Ruby 1.9.3
|
25
|
+
Enabled: false
|
26
|
+
|
data/.travis.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
+
- 2.4
|
5
|
+
- 2.3
|
4
6
|
- 2.2
|
5
7
|
- 2.0.0
|
6
8
|
- 2.1
|
@@ -32,6 +34,6 @@ before_install:
|
|
32
34
|
notifications:
|
33
35
|
email:
|
34
36
|
recipients:
|
35
|
-
-
|
37
|
+
- ruby-cloud-eng@google.com
|
36
38
|
on_success: change
|
37
39
|
on_failure: change
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
## 0.5.
|
1
|
+
## 0.5.2 (2017/07/19)
|
2
|
+
|
3
|
+
### Changes
|
4
|
+
|
5
|
+
* Add retry mechanism when fetching access tokens in `GCECredentials` and `UserRefreshCredentials` classes.
|
6
|
+
* Update Google API OAuth2 token credential URI to v4.
|
7
|
+
|
8
|
+
## 0.5.1 (2016/01/06)
|
2
9
|
|
3
10
|
### Changes
|
4
11
|
|
@@ -6,14 +13,14 @@
|
|
6
13
|
* Fix ADC not working on some windows machines ([@vsubramani][])
|
7
14
|
[#55](https://github.com/google/google-auth-library-ruby/issues/55)
|
8
15
|
|
9
|
-
## 0.5.0 (
|
16
|
+
## 0.5.0 (2015/10/12)
|
10
17
|
|
11
18
|
### Changes
|
12
19
|
|
13
20
|
* Initial support for user credentials ([@sqrrrl][])
|
14
21
|
* Update Signet to 0.7
|
15
22
|
|
16
|
-
## 0.4.2 (
|
23
|
+
## 0.4.2 (2015/08/05)
|
17
24
|
|
18
25
|
### Changes
|
19
26
|
|
@@ -34,20 +41,20 @@
|
|
34
41
|
* Enables passing credentials via environment variables. ([@haabaato][])
|
35
42
|
[#27](https://github.com/google/google-auth-library-ruby/issues/27)
|
36
43
|
|
37
|
-
## 0.4.1 (
|
44
|
+
## 0.4.1 (2015/04/25)
|
38
45
|
|
39
46
|
### Changes
|
40
47
|
|
41
48
|
* Improves handling of --no-scopes GCE authorization ([@tbetbetbe][])
|
42
49
|
* Refactoring and cleanup ([@joneslee85][])
|
43
50
|
|
44
|
-
## 0.4.0 (
|
51
|
+
## 0.4.0 (2015/03/25)
|
45
52
|
|
46
53
|
### Changes
|
47
54
|
|
48
55
|
* Adds an implementation of JWT header auth ([@tbetbetbe][])
|
49
56
|
|
50
|
-
## 0.3.0 (
|
57
|
+
## 0.3.0 (2015/03/23)
|
51
58
|
|
52
59
|
### Changes
|
53
60
|
|
data/Gemfile
CHANGED
@@ -5,17 +5,17 @@ gemspec
|
|
5
5
|
|
6
6
|
group :development do
|
7
7
|
gem 'bundler', '~> 1.9'
|
8
|
-
gem 'simplecov', '~> 0.9'
|
9
8
|
gem 'coveralls', '~> 0.7'
|
10
9
|
gem 'fakefs', '~> 0.6'
|
11
|
-
gem 'rake', '~> 10.0'
|
12
|
-
gem 'rubocop', '~> 0.30'
|
13
|
-
gem 'rspec', '~> 3.0'
|
14
|
-
gem 'redis', '~> 3.2'
|
15
10
|
gem 'fakeredis', '~> 0.5'
|
16
|
-
gem 'webmock', '~> 1.21'
|
17
11
|
gem 'rack-test', '~> 0.6'
|
12
|
+
gem 'rake', '~> 10.0'
|
13
|
+
gem 'redis', '~> 3.2'
|
14
|
+
gem 'rspec', '~> 3.0'
|
15
|
+
gem 'rubocop', '~> 0.30'
|
16
|
+
gem 'simplecov', '~> 0.9'
|
18
17
|
gem 'sinatra'
|
18
|
+
gem 'webmock', '~> 1.21'
|
19
19
|
end
|
20
20
|
|
21
21
|
platforms :jruby do
|
data/README.md
CHANGED
@@ -70,7 +70,7 @@ a generic authorizer useful for command line apps or custom integrations as
|
|
70
70
|
well as a web variant tailored toward Rack-based applications.
|
71
71
|
|
72
72
|
The authorizers are intended for authorization use cases. For sign-on,
|
73
|
-
see [Google
|
73
|
+
see [Google Identity Platform](https://developers.google.com/identity/)
|
74
74
|
|
75
75
|
### Example (Web)
|
76
76
|
|
@@ -92,7 +92,7 @@ get('/authorize') do
|
|
92
92
|
user_id = request.session['user_id']
|
93
93
|
credentials = authorizer.get_credentials(user_id, request)
|
94
94
|
if credentials.nil?
|
95
|
-
redirect authorizer.get_authorization_url(
|
95
|
+
redirect authorizer.get_authorization_url(login_hint: user_id, request: request)
|
96
96
|
end
|
97
97
|
# Credentials are valid, can call APIs
|
98
98
|
# ...
|
@@ -111,6 +111,8 @@ end
|
|
111
111
|
require 'googleauth'
|
112
112
|
require 'googleauth/stores/file_token_store'
|
113
113
|
|
114
|
+
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
|
115
|
+
|
114
116
|
scope = 'https://www.googleapis.com/auth/drive'
|
115
117
|
client_id = Google::Auth::ClientId.from_file('/path/to/client_secrets.json')
|
116
118
|
token_store = Google::Auth::Stores::FileTokenStore.new(
|
@@ -119,7 +121,7 @@ authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
|
|
119
121
|
|
120
122
|
credentials = authorizer.get_credentials(user_id)
|
121
123
|
if credentials.nil?
|
122
|
-
url = authorizer.get_authorization_url(base_url:
|
124
|
+
url = authorizer.get_authorization_url(base_url: OOB_URI )
|
123
125
|
puts "Open #{url} in your browser and enter the resulting code:"
|
124
126
|
code = gets
|
125
127
|
credentials = authorizer.get_and_store_credentials_from_code(
|
@@ -129,6 +131,18 @@ end
|
|
129
131
|
# OK to use credentials
|
130
132
|
```
|
131
133
|
|
134
|
+
### Example (Service Account)
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
scope = 'https://www.googleapis.com/auth/androidpublisher'
|
138
|
+
|
139
|
+
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
|
140
|
+
json_key_io: File.open('/path/to/service_account_json_key.json'),
|
141
|
+
scope: scope)
|
142
|
+
|
143
|
+
authorizer.fetch_access_token!
|
144
|
+
```
|
145
|
+
|
132
146
|
### Storage
|
133
147
|
|
134
148
|
Authorizers require a storage instance to manage long term persistence of
|
@@ -140,14 +154,6 @@ access and refresh tokens. Two storage implementations are included:
|
|
140
154
|
Custom storage implementations can also be used. See
|
141
155
|
[token_store.rb](lib/googleauth/token_store.rb) for additional details.
|
142
156
|
|
143
|
-
## What about auth in google-apis-ruby-client?
|
144
|
-
|
145
|
-
The goal is for all auth done by
|
146
|
-
[google-apis-ruby-client][google-apis-ruby-client] to be performed by this
|
147
|
-
library. I.e, eventually google-apis-ruby-client will just take a dependency
|
148
|
-
on this library. This update is a work in progress, but should be completed
|
149
|
-
by Q2 2015.
|
150
|
-
|
151
157
|
## License
|
152
158
|
|
153
159
|
This library is licensed under Apache 2.0. Full license text is
|
data/googleauth.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
# encoding: utf-8
|
3
|
+
|
3
4
|
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
4
5
|
require 'googleauth/version'
|
5
6
|
|
@@ -25,7 +26,7 @@ Gem::Specification.new do |s|
|
|
25
26
|
s.require_paths = ['lib']
|
26
27
|
s.platform = Gem::Platform::RUBY
|
27
28
|
|
28
|
-
s.add_dependency 'faraday', '~> 0.
|
29
|
+
s.add_dependency 'faraday', '~> 0.12'
|
29
30
|
s.add_dependency 'logging', '~> 2.0'
|
30
31
|
s.add_dependency 'jwt', '~> 1.4'
|
31
32
|
s.add_dependency 'memoist', '~> 0.12'
|
data/lib/googleauth.rb
CHANGED
@@ -42,7 +42,7 @@ module Google
|
|
42
42
|
# Module Auth provides classes that provide Google-specific authorization
|
43
43
|
# used to access Google APIs.
|
44
44
|
module Auth
|
45
|
-
NOT_FOUND_ERROR = <<END
|
45
|
+
NOT_FOUND_ERROR = <<END.freeze
|
46
46
|
Could not load the default credentials. Browse to
|
47
47
|
https://developers.google.com/accounts/docs/application-default-credentials
|
48
48
|
for more information
|
@@ -70,14 +70,14 @@ END
|
|
70
70
|
def self.read_creds
|
71
71
|
env_var = CredentialsLoader::ACCOUNT_TYPE_VAR
|
72
72
|
type = ENV[env_var]
|
73
|
-
|
73
|
+
raise "#{env_var} is undefined in env" unless type
|
74
74
|
case type
|
75
75
|
when 'service_account'
|
76
76
|
ServiceAccountCredentials
|
77
77
|
when 'authorized_user'
|
78
78
|
UserRefreshCredentials
|
79
79
|
else
|
80
|
-
|
80
|
+
raise "credentials type '#{type}' is not supported"
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -85,7 +85,7 @@ END
|
|
85
85
|
def self.determine_creds_class(json_key_io)
|
86
86
|
json_key = MultiJson.load(json_key_io.read)
|
87
87
|
key = 'type'
|
88
|
-
|
88
|
+
raise "the json is missing the '#{key}' field" unless json_key.key?(key)
|
89
89
|
type = json_key[key]
|
90
90
|
case type
|
91
91
|
when 'service_account'
|
@@ -93,7 +93,7 @@ END
|
|
93
93
|
when 'authorized_user'
|
94
94
|
[json_key, UserRefreshCredentials]
|
95
95
|
else
|
96
|
-
|
96
|
+
raise "credentials type '#{type}' is not supported"
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
@@ -116,7 +116,7 @@ END
|
|
116
116
|
DefaultCredentials.from_well_known_path(scope) ||
|
117
117
|
DefaultCredentials.from_system_default_path(scope)
|
118
118
|
return creds unless creds.nil?
|
119
|
-
|
119
|
+
raise NOT_FOUND_ERROR unless GCECredentials.on_gce?(options)
|
120
120
|
GCECredentials.new
|
121
121
|
end
|
122
122
|
|
data/lib/googleauth/client_id.rb
CHANGED
@@ -34,12 +34,12 @@ module Google
|
|
34
34
|
# Representation of an application's identity for user authorization
|
35
35
|
# flows.
|
36
36
|
class ClientId
|
37
|
-
INSTALLED_APP = 'installed'
|
38
|
-
WEB_APP = 'web'
|
39
|
-
CLIENT_ID = 'client_id'
|
40
|
-
CLIENT_SECRET = 'client_secret'
|
37
|
+
INSTALLED_APP = 'installed'.freeze
|
38
|
+
WEB_APP = 'web'.freeze
|
39
|
+
CLIENT_ID = 'client_id'.freeze
|
40
|
+
CLIENT_SECRET = 'client_secret'.freeze
|
41
41
|
MISSING_TOP_LEVEL_ELEMENT_ERROR =
|
42
|
-
"Expected top level property 'installed' or 'web' to be present."
|
42
|
+
"Expected top level property 'installed' or 'web' to be present.".freeze
|
43
43
|
|
44
44
|
# Text identifier of the client ID
|
45
45
|
# @return [String]
|
@@ -63,8 +63,8 @@ module Google
|
|
63
63
|
# & secrets in source. See {#from_file} to load from
|
64
64
|
# `client_secrets.json` files.
|
65
65
|
def initialize(id, secret)
|
66
|
-
|
67
|
-
|
66
|
+
raise 'Client id can not be nil' if id.nil?
|
67
|
+
raise 'Client secret can not be nil' if secret.nil?
|
68
68
|
@id = id
|
69
69
|
@secret = secret
|
70
70
|
end
|
@@ -76,7 +76,7 @@ module Google
|
|
76
76
|
# Path of file to read from
|
77
77
|
# @return [Google::Auth::ClientID]
|
78
78
|
def self.from_file(file)
|
79
|
-
|
79
|
+
raise 'File can not be nil.' if file.nil?
|
80
80
|
File.open(file.to_s) do |f|
|
81
81
|
json = f.read
|
82
82
|
config = MultiJson.load(json)
|
@@ -92,9 +92,9 @@ module Google
|
|
92
92
|
# Parsed contents of the JSON file
|
93
93
|
# @return [Google::Auth::ClientID]
|
94
94
|
def self.from_hash(config)
|
95
|
-
|
95
|
+
raise 'Hash can not be nil.' if config.nil?
|
96
96
|
raw_detail = config[INSTALLED_APP] || config[WEB_APP]
|
97
|
-
|
97
|
+
raise MISSING_TOP_LEVEL_ELEMENT_ERROR if raw_detail.nil?
|
98
98
|
ClientId.new(raw_detail[CLIENT_ID], raw_detail[CLIENT_SECRET])
|
99
99
|
end
|
100
100
|
end
|
@@ -35,13 +35,13 @@ module Google
|
|
35
35
|
# Module Auth provides classes that provide Google-specific authorization
|
36
36
|
# used to access Google APIs.
|
37
37
|
module Auth
|
38
|
-
NO_METADATA_SERVER_ERROR = <<END
|
38
|
+
NO_METADATA_SERVER_ERROR = <<END.freeze
|
39
39
|
Error code 404 trying to get security access token
|
40
40
|
from Compute Engine metadata for the default service account. This
|
41
41
|
may be because the virtual machine instance does not have permission
|
42
42
|
scopes specified.
|
43
43
|
END
|
44
|
-
UNEXPECTED_ERROR_SUFFIX = <<END
|
44
|
+
UNEXPECTED_ERROR_SUFFIX = <<END.freeze
|
45
45
|
trying to get security access token from Compute Engine metadata for
|
46
46
|
the default service account
|
47
47
|
END
|
@@ -52,8 +52,8 @@ END
|
|
52
52
|
# The IP Address is used in the URIs to speed up failures on non-GCE
|
53
53
|
# systems.
|
54
54
|
COMPUTE_AUTH_TOKEN_URI = 'http://169.254.169.254/computeMetadata/v1/'\
|
55
|
-
'instance/service-accounts/default/token'
|
56
|
-
COMPUTE_CHECK_URI = 'http://169.254.169.254'
|
55
|
+
'instance/service-accounts/default/token'.freeze
|
56
|
+
COMPUTE_CHECK_URI = 'http://169.254.169.254'.freeze
|
57
57
|
|
58
58
|
class << self
|
59
59
|
extend Memoist
|
@@ -88,16 +88,20 @@ END
|
|
88
88
|
def fetch_access_token(options = {})
|
89
89
|
c = options[:connection] || Faraday.default_connection
|
90
90
|
c.headers = { 'Metadata-Flavor' => 'Google' }
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
91
|
+
|
92
|
+
retry_with_error do
|
93
|
+
resp = c.get(COMPUTE_AUTH_TOKEN_URI)
|
94
|
+
case resp.status
|
95
|
+
when 200
|
96
|
+
Signet::OAuth2.parse_credentials(resp.body,
|
97
|
+
resp.headers['content-type'])
|
98
|
+
when 404
|
99
|
+
raise(Signet::AuthorizationError, NO_METADATA_SERVER_ERROR)
|
100
|
+
else
|
101
|
+
msg = "Unexpected error code #{resp.status}" \
|
102
|
+
"#{UNEXPECTED_ERROR_SUFFIX}"
|
103
|
+
raise(Signet::AuthorizationError, msg)
|
104
|
+
end
|
101
105
|
end
|
102
106
|
end
|
103
107
|
end
|
@@ -39,22 +39,23 @@ module Google
|
|
39
39
|
# credentials files on the file system.
|
40
40
|
module CredentialsLoader
|
41
41
|
extend Memoist
|
42
|
-
ENV_VAR = 'GOOGLE_APPLICATION_CREDENTIALS'
|
42
|
+
ENV_VAR = 'GOOGLE_APPLICATION_CREDENTIALS'.freeze
|
43
43
|
|
44
|
-
PRIVATE_KEY_VAR = 'GOOGLE_PRIVATE_KEY'
|
45
|
-
CLIENT_EMAIL_VAR = 'GOOGLE_CLIENT_EMAIL'
|
46
|
-
CLIENT_ID_VAR = 'GOOGLE_CLIENT_ID'
|
47
|
-
CLIENT_SECRET_VAR = 'GOOGLE_CLIENT_SECRET'
|
48
|
-
REFRESH_TOKEN_VAR = 'GOOGLE_REFRESH_TOKEN'
|
49
|
-
ACCOUNT_TYPE_VAR = 'GOOGLE_ACCOUNT_TYPE'
|
44
|
+
PRIVATE_KEY_VAR = 'GOOGLE_PRIVATE_KEY'.freeze
|
45
|
+
CLIENT_EMAIL_VAR = 'GOOGLE_CLIENT_EMAIL'.freeze
|
46
|
+
CLIENT_ID_VAR = 'GOOGLE_CLIENT_ID'.freeze
|
47
|
+
CLIENT_SECRET_VAR = 'GOOGLE_CLIENT_SECRET'.freeze
|
48
|
+
REFRESH_TOKEN_VAR = 'GOOGLE_REFRESH_TOKEN'.freeze
|
49
|
+
ACCOUNT_TYPE_VAR = 'GOOGLE_ACCOUNT_TYPE'.freeze
|
50
50
|
|
51
|
-
CREDENTIALS_FILE_NAME = 'application_default_credentials.json'
|
51
|
+
CREDENTIALS_FILE_NAME = 'application_default_credentials.json'.freeze
|
52
52
|
NOT_FOUND_ERROR =
|
53
|
-
"Unable to read the credential file specified by #{ENV_VAR}"
|
54
|
-
WELL_KNOWN_PATH = "gcloud/#{CREDENTIALS_FILE_NAME}"
|
55
|
-
WELL_KNOWN_ERROR = 'Unable to read the default credential file'
|
53
|
+
"Unable to read the credential file specified by #{ENV_VAR}".freeze
|
54
|
+
WELL_KNOWN_PATH = "gcloud/#{CREDENTIALS_FILE_NAME}".freeze
|
55
|
+
WELL_KNOWN_ERROR = 'Unable to read the default credential file'.freeze
|
56
56
|
|
57
|
-
SYSTEM_DEFAULT_ERROR =
|
57
|
+
SYSTEM_DEFAULT_ERROR =
|
58
|
+
'Unable to read the system default credential file'.freeze
|
58
59
|
|
59
60
|
# make_creds proxies the construction of a credentials instance
|
60
61
|
#
|
@@ -71,7 +72,7 @@ module Google
|
|
71
72
|
def from_env(scope = nil)
|
72
73
|
if ENV.key?(ENV_VAR)
|
73
74
|
path = ENV[ENV_VAR]
|
74
|
-
|
75
|
+
raise "file #{path} does not exist" unless File.exist?(path)
|
75
76
|
File.open(path) do |f|
|
76
77
|
return make_creds(json_key_io: f, scope: scope)
|
77
78
|
end
|
data/lib/googleauth/iam.rb
CHANGED
@@ -37,16 +37,16 @@ module Google
|
|
37
37
|
module Auth
|
38
38
|
# Authenticates requests using IAM credentials.
|
39
39
|
class IAMCredentials
|
40
|
-
SELECTOR_KEY = 'x-goog-iam-authority-selector'
|
41
|
-
TOKEN_KEY = 'x-goog-iam-authorization-token'
|
40
|
+
SELECTOR_KEY = 'x-goog-iam-authority-selector'.freeze
|
41
|
+
TOKEN_KEY = 'x-goog-iam-authorization-token'.freeze
|
42
42
|
|
43
43
|
# Initializes an IAMCredentials.
|
44
44
|
#
|
45
45
|
# @param selector the IAM selector.
|
46
46
|
# @param token the IAM token.
|
47
47
|
def initialize(selector, token)
|
48
|
-
|
49
|
-
|
48
|
+
raise TypeError unless selector.is_a? String
|
49
|
+
raise TypeError unless token.is_a? String
|
50
50
|
@selector = selector
|
51
51
|
@token = token
|
52
52
|
end
|
@@ -39,7 +39,7 @@ module Google
|
|
39
39
|
'email' => 'https://www.googleapis.com/auth/userinfo.email',
|
40
40
|
'profile' => 'https://www.googleapis.com/auth/userinfo.profile',
|
41
41
|
'openid' => 'https://www.googleapis.com/auth/plus.me'
|
42
|
-
}
|
42
|
+
}.freeze
|
43
43
|
|
44
44
|
def self.normalize(scope)
|
45
45
|
list = as_array(scope)
|
@@ -53,7 +53,7 @@ module Google
|
|
53
53
|
when String
|
54
54
|
scope.split(' ')
|
55
55
|
else
|
56
|
-
|
56
|
+
raise 'Invalid scope value. Must be string or array'
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|