googleauth-extras 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +28 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +47 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +14 -0
- data/LICENSE +21 -0
- data/README.md +72 -0
- data/Rakefile +11 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/googleauth-extras.gemspec +38 -0
- data/lib/google/auth/extras/impersonated_credential.rb +77 -0
- data/lib/google/auth/extras/static_credential.rb +32 -0
- data/lib/google/auth/extras/token_info.rb +60 -0
- data/lib/google/auth/extras/version.rb +9 -0
- data/lib/google/auth/extras.rb +70 -0
- data/lib/googleauth/extras.rb +5 -0
- metadata +143 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0a86b0a5307d997f90698df100b415f4a21d91b8a40f81758449ec3876b3eb86
|
|
4
|
+
data.tar.gz: 024a30daaed45790e9febd782300d197e5a9e0dd1494015912e07b34ceb081f5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d102b3fb295efc23afef1a4f945bff1a016e203fc25c73321ad3e4705854969a4fc8918bb37ac130b95c25804b8803a3ec86de468544bb797d67a41b90b7717c
|
|
7
|
+
data.tar.gz: c04a1a5fadc7e6cc4c8f378f479285de2c537b190cd08ee3685930d48d855edfb0dc993d69a35419329eef99ce69e36c724e50a7894a714668a4814c7380a9ad
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
strategy:
|
|
14
|
+
fail-fast: false
|
|
15
|
+
matrix:
|
|
16
|
+
ruby:
|
|
17
|
+
- '2.7'
|
|
18
|
+
- '3.0'
|
|
19
|
+
- '3.1'
|
|
20
|
+
- '3.2'
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v3
|
|
24
|
+
- uses: ruby/setup-ruby@v1
|
|
25
|
+
with:
|
|
26
|
+
bundler-cache: true
|
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
|
28
|
+
- run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
|
|
4
|
+
AllCops:
|
|
5
|
+
NewCops: enable
|
|
6
|
+
|
|
7
|
+
Layout/FirstHashElementIndentation:
|
|
8
|
+
EnforcedStyle: consistent
|
|
9
|
+
|
|
10
|
+
Layout/LineLength:
|
|
11
|
+
Max: 160
|
|
12
|
+
|
|
13
|
+
Metrics/AbcSize:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Max: 20
|
|
18
|
+
|
|
19
|
+
Metrics/ParameterLists:
|
|
20
|
+
Enabled: false
|
|
21
|
+
|
|
22
|
+
RSpec/ContextWording:
|
|
23
|
+
Enabled: false
|
|
24
|
+
|
|
25
|
+
RSpec/ExampleLength:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
RSpec/MultipleExpectations:
|
|
29
|
+
Max: 50
|
|
30
|
+
|
|
31
|
+
RSpec/NamedSubject:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
Style/ModuleFunction:
|
|
35
|
+
EnforcedStyle: extend_self
|
|
36
|
+
|
|
37
|
+
Style/NumericLiterals:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
Style/StringLiterals:
|
|
41
|
+
EnforcedStyle: single_quotes
|
|
42
|
+
|
|
43
|
+
Style/TrailingCommaInArguments:
|
|
44
|
+
EnforcedStyleForMultiline: comma
|
|
45
|
+
|
|
46
|
+
Style/TrailingCommaInHashLiteral:
|
|
47
|
+
EnforcedStyleForMultiline: comma
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in googleauth-extras.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
gem 'pry-byebug', '~> 3.10'
|
|
9
|
+
gem 'rake', '~> 12.0'
|
|
10
|
+
gem 'rspec', '~> 3.0'
|
|
11
|
+
gem 'rubocop', '~> 1.45'
|
|
12
|
+
gem 'rubocop-rspec', '~> 2.18'
|
|
13
|
+
gem 'timecop', '~> 0.9.6'
|
|
14
|
+
gem 'webmock', '~> 3.18'
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Persona
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# googleauth-extras
|
|
2
|
+
|
|
3
|
+
**Disclaimer: This gem is not sponsored by Google.**
|
|
4
|
+
|
|
5
|
+
The [googleauth](https://github.com/googleapis/google-auth-library-ruby) currently lacks support for all the authentication schemes supported in Python and the `gcloud` CLI. This gem aims to support additional schemes like:
|
|
6
|
+
|
|
7
|
+
- Impersonated credentials
|
|
8
|
+
- Static credentials
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add this line to your application's Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'googleauth-extras'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
$ bundle install
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
|
|
24
|
+
$ gem install googleauth-extras
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Impersonated Credentials
|
|
29
|
+
|
|
30
|
+
If you'd like to have credentials that act as a different service account, you can setup the credentials with:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
Google::Apis::DriveV3::DriveService.new.tap do |ds|
|
|
34
|
+
ds.authorization = Google::Auth::Extras.impersonated_credential(
|
|
35
|
+
email_address: 'my-sa@my-project.iam.gserviceaccount.com',
|
|
36
|
+
scope: [
|
|
37
|
+
Google::Apis::SheetsV4::AUTH_DRIVE,
|
|
38
|
+
],
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
You can optionally specify the following additional options:
|
|
44
|
+
|
|
45
|
+
- `base_credentials`: The credentials to use to make the impersonation call. If not specified, uses the standard SDK credential resolution process.
|
|
46
|
+
- `delegate_email_addresses`: If there are intermediate service accounts that need to be impersonated using [delegation](https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated#sa-credentials-permissions), the list of email addresses.
|
|
47
|
+
- `lifetime`: The desired lifetime [in seconds](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateAccessToken), defaulting to 1h.
|
|
48
|
+
|
|
49
|
+
### Static Credentials
|
|
50
|
+
|
|
51
|
+
If you'd like to use a static access token, you can setup the credentials with:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
# Old API Client
|
|
55
|
+
Google::Apis::RequestOptions.default.authorization = Google::Auth::Extras.static_credential('my-access-token')
|
|
56
|
+
# New API Client
|
|
57
|
+
Google::Cloud.configure.credentials = Google::Auth::Extras.static_credential('my-access-token')
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Development
|
|
61
|
+
|
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
63
|
+
|
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
|
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/persona-id/googleauth-extras.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'googleauth/extras'
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
require 'pry'
|
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/google/auth/extras/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'googleauth-extras'
|
|
7
|
+
spec.version = Google::Auth::Extras::VERSION
|
|
8
|
+
spec.authors = ['Persona Identities']
|
|
9
|
+
spec.email = ['alex.coomans@withpersona.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Additions to the googleauth gem for unsupported authentication schemes.'
|
|
12
|
+
spec.homepage = 'https://github.com/persona-id/googleauth-extras'
|
|
13
|
+
spec.license = 'MIT'
|
|
14
|
+
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
|
16
|
+
|
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
18
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
19
|
+
|
|
20
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
21
|
+
spec.metadata['source_code_uri'] = 'https://github.com/persona-id/googleauth-extras'
|
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/persona-id/googleauth-extras/blob/main/CHANGELOG.md'
|
|
23
|
+
|
|
24
|
+
# Specify which files should be added to the gem when it is released.
|
|
25
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
28
|
+
end
|
|
29
|
+
spec.bindir = 'exe'
|
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
31
|
+
spec.require_paths = ['lib']
|
|
32
|
+
|
|
33
|
+
spec.add_runtime_dependency 'addressable', '~> 2.8'
|
|
34
|
+
spec.add_runtime_dependency 'faraday', '>= 1.0', '< 3.0'
|
|
35
|
+
spec.add_runtime_dependency 'google-apis-iamcredentials_v1'
|
|
36
|
+
spec.add_runtime_dependency 'googleauth', '~> 1.3'
|
|
37
|
+
spec.add_runtime_dependency 'signet', '~> 0.17.0'
|
|
38
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Google
|
|
4
|
+
module Auth
|
|
5
|
+
module Extras
|
|
6
|
+
# This credential impersonates a service account.
|
|
7
|
+
class ImpersonatedCredential < Signet::OAuth2::Client
|
|
8
|
+
class MissingScope < StandardError; end
|
|
9
|
+
|
|
10
|
+
# A credential that impersonates a service account.
|
|
11
|
+
#
|
|
12
|
+
# @param base_credentials [Hash, String, Signet::OAuth2::Client]
|
|
13
|
+
# Credentials to use to impersonate the provided email address.
|
|
14
|
+
#
|
|
15
|
+
# @param delegate_email_addresses [String, Array<String>]
|
|
16
|
+
# The list of email address if there are intermediate service accounts that
|
|
17
|
+
# need to be impersonated using delegation.
|
|
18
|
+
#
|
|
19
|
+
# @param email_address [String]
|
|
20
|
+
# Email of the service account to impersonate.
|
|
21
|
+
#
|
|
22
|
+
# @param lifetime [String]
|
|
23
|
+
# The desired lifetime (in seconds) of the token before needing to be refreshed.
|
|
24
|
+
# Defaults to 1h, adjust as needed given a refresh is automatically performed
|
|
25
|
+
# when the token less than 60s of remaining life and refresh requires an
|
|
26
|
+
# additional API call.
|
|
27
|
+
#
|
|
28
|
+
# @param scope [String, Array<String>]
|
|
29
|
+
# The OAuth 2 scopes to request. Can either be formatted as a comma seperated string or array.
|
|
30
|
+
#
|
|
31
|
+
# @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateAccessToken
|
|
32
|
+
# @see https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated#sa-credentials-permissions
|
|
33
|
+
#
|
|
34
|
+
def initialize(email_address:, scope:, base_credentials: nil, delegate_email_addresses: nil, lifetime: nil)
|
|
35
|
+
super(scope: scope)
|
|
36
|
+
|
|
37
|
+
raise MissingScope if self.scope.nil? || self.scope.empty?
|
|
38
|
+
|
|
39
|
+
@iam_credentials_service = Google::Apis::IamcredentialsV1::IAMCredentialsService.new.tap do |ics|
|
|
40
|
+
ics.authorization = base_credentials if base_credentials
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
@impersonate_delegates = Array(delegate_email_addresses).map do |email|
|
|
44
|
+
transform_email_to_name(email)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
@impersonate_lifetime = lifetime
|
|
48
|
+
|
|
49
|
+
@impersonate_name = transform_email_to_name(email_address)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def fetch_access_token(*)
|
|
53
|
+
access_token_request = Google::Apis::IamcredentialsV1::GenerateAccessTokenRequest.new(
|
|
54
|
+
scope: scope,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# The Google SDK doesn't like nil repeated values, but be careful with others as well.
|
|
58
|
+
access_token_request.delegates = @impersonate_delegates unless @impersonate_delegates.empty?
|
|
59
|
+
access_token_request.lifetime = @impersonate_lifetime unless @impersonate_lifetime.nil?
|
|
60
|
+
|
|
61
|
+
access_token_response = @iam_credentials_service.generate_service_account_access_token(@impersonate_name, access_token_request)
|
|
62
|
+
|
|
63
|
+
{
|
|
64
|
+
access_token: access_token_response.access_token,
|
|
65
|
+
expires_at: DateTime.rfc3339(access_token_response.expire_time).to_time,
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def transform_email_to_name(email)
|
|
72
|
+
"projects/-/serviceAccounts/#{email}"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Google
|
|
4
|
+
module Auth
|
|
5
|
+
module Extras
|
|
6
|
+
# This credential uses a static access token.
|
|
7
|
+
class StaticCredential < Signet::OAuth2::Client
|
|
8
|
+
class AuthorizationExpired < StandardError; end
|
|
9
|
+
|
|
10
|
+
# A credential using a static access token.
|
|
11
|
+
#
|
|
12
|
+
# @param access_token [String]
|
|
13
|
+
# The access token to use.
|
|
14
|
+
#
|
|
15
|
+
def initialize(access_token:)
|
|
16
|
+
super(
|
|
17
|
+
access_token: access_token,
|
|
18
|
+
expires_at: TokenInfo.lookup_access_token(access_token).fetch('exp'),
|
|
19
|
+
issued_at: nil,
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def fetch_access_token(*)
|
|
24
|
+
raise RefreshNotSupported
|
|
25
|
+
rescue RefreshNotSupported
|
|
26
|
+
# This is a simple trick for getting the cause to be set.
|
|
27
|
+
raise Signet::AuthorizationError, 'Refresh not supported'
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Google
|
|
4
|
+
module Auth
|
|
5
|
+
module Extras
|
|
6
|
+
# This module provides methods to lookup details about authenication tokens,
|
|
7
|
+
# primarily for their expiration.
|
|
8
|
+
module TokenInfo
|
|
9
|
+
extend self
|
|
10
|
+
|
|
11
|
+
class LookupFailed < StandardError; end
|
|
12
|
+
class LookupMalformed < LookupFailed; end
|
|
13
|
+
|
|
14
|
+
TOKEN_INFO_URI = 'https://oauth2.googleapis.com/tokeninfo'
|
|
15
|
+
private_constant :TOKEN_INFO_URI
|
|
16
|
+
|
|
17
|
+
# Lookup the details for a valid access token, including it's expiration.
|
|
18
|
+
#
|
|
19
|
+
# @raise [LookupFailed]
|
|
20
|
+
# If the token is invalid (including expired).
|
|
21
|
+
#
|
|
22
|
+
# @return [Hash]
|
|
23
|
+
#
|
|
24
|
+
# @see https://cloud.google.com/docs/authentication/token-types#access-contents
|
|
25
|
+
#
|
|
26
|
+
def lookup_access_token(token)
|
|
27
|
+
lookup(access_token: token)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def lookup(query)
|
|
33
|
+
url = Addressable::URI.parse(TOKEN_INFO_URI)
|
|
34
|
+
url.query_values = query
|
|
35
|
+
|
|
36
|
+
response = Faraday.default_connection.get(url.normalize.to_s)
|
|
37
|
+
|
|
38
|
+
raise LookupFailed, response.body.to_s unless response.status == 200
|
|
39
|
+
|
|
40
|
+
credentials = Signet::OAuth2.parse_credentials(response.body, response.headers['Content-Type'])
|
|
41
|
+
|
|
42
|
+
raise LookupMalformed, 'Missing token expiry' unless credentials['exp']
|
|
43
|
+
|
|
44
|
+
credentials['exp'] = parse_as_integer(credentials['exp'])
|
|
45
|
+
credentials['expires_in'] = parse_as_integer(credentials['expires_in'])
|
|
46
|
+
|
|
47
|
+
credentials.transform_values(&:freeze).freeze
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def parse_as_integer(str)
|
|
51
|
+
return nil if str.nil?
|
|
52
|
+
|
|
53
|
+
str.to_i.tap do |value|
|
|
54
|
+
raise LookupMalformed unless value.to_s == str
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'date'
|
|
4
|
+
require 'google/apis/iamcredentials_v1'
|
|
5
|
+
require 'signet/oauth_2/client'
|
|
6
|
+
|
|
7
|
+
require 'google/auth/extras/impersonated_credential'
|
|
8
|
+
require 'google/auth/extras/static_credential'
|
|
9
|
+
require 'google/auth/extras/token_info'
|
|
10
|
+
require 'google/auth/extras/version'
|
|
11
|
+
|
|
12
|
+
module Google
|
|
13
|
+
module Auth
|
|
14
|
+
# This module provides some extra features not supported in the normal googleauth gem.
|
|
15
|
+
module Extras
|
|
16
|
+
extend self
|
|
17
|
+
|
|
18
|
+
# Raised when a credential does not support refresh, like a static
|
|
19
|
+
# credential.
|
|
20
|
+
class RefreshNotSupported < StandardError; end
|
|
21
|
+
|
|
22
|
+
# A credential that impersonates a service account.
|
|
23
|
+
#
|
|
24
|
+
# @param base_credentials [Hash, String, Signet::OAuth2::Client]
|
|
25
|
+
# Credentials to use to impersonate the provided email address.
|
|
26
|
+
#
|
|
27
|
+
# @param delegate_email_addresses [String, Array<String>]
|
|
28
|
+
# The list of email address if there are intermediate service accounts that
|
|
29
|
+
# need to be impersonated using delegation.
|
|
30
|
+
#
|
|
31
|
+
# @param email_address [String]
|
|
32
|
+
# Email of the service account to impersonate.
|
|
33
|
+
#
|
|
34
|
+
# @param lifetime [String]
|
|
35
|
+
# The desired lifetime (in seconds) of the token before needing to be refreshed.
|
|
36
|
+
# Defaults to 1h, adjust as needed given a refresh is automatically performed
|
|
37
|
+
# when the token less than 60s of remaining life and refresh requires an
|
|
38
|
+
# additional API call.
|
|
39
|
+
#
|
|
40
|
+
# @param scope [String, Array<String>]
|
|
41
|
+
# The OAuth 2 scopes to request. Can either be formatted as a comma seperated string or array.
|
|
42
|
+
#
|
|
43
|
+
# @return [Google::Auth::Extras::ImpersonatedCredential]
|
|
44
|
+
#
|
|
45
|
+
# @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateAccessToken
|
|
46
|
+
# @see https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated#sa-credentials-permissions
|
|
47
|
+
#
|
|
48
|
+
def impersonated_credential(email_address:, scope:, base_credentials: nil, delegate_email_addresses: nil, lifetime: nil)
|
|
49
|
+
ImpersonatedCredential.new(
|
|
50
|
+
base_credentials: base_credentials,
|
|
51
|
+
delegate_email_addresses: delegate_email_addresses,
|
|
52
|
+
email_address: email_address,
|
|
53
|
+
lifetime: lifetime,
|
|
54
|
+
scope: scope,
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# A credential using a static access token token.
|
|
59
|
+
#
|
|
60
|
+
# @param token [String]
|
|
61
|
+
# The access token to use.
|
|
62
|
+
#
|
|
63
|
+
# @return [Google::Auth::Extras::StaticCredential]
|
|
64
|
+
#
|
|
65
|
+
def static_credential(token)
|
|
66
|
+
StaticCredential.new(access_token: token)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: googleauth-extras
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Persona Identities
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: addressable
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.8'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.8'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: faraday
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.0'
|
|
34
|
+
- - "<"
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '3.0'
|
|
37
|
+
type: :runtime
|
|
38
|
+
prerelease: false
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '1.0'
|
|
44
|
+
- - "<"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '3.0'
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: google-apis-iamcredentials_v1
|
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :runtime
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: googleauth
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '1.3'
|
|
68
|
+
type: :runtime
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '1.3'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: signet
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 0.17.0
|
|
82
|
+
type: :runtime
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 0.17.0
|
|
89
|
+
description:
|
|
90
|
+
email:
|
|
91
|
+
- alex.coomans@withpersona.com
|
|
92
|
+
executables: []
|
|
93
|
+
extensions: []
|
|
94
|
+
extra_rdoc_files: []
|
|
95
|
+
files:
|
|
96
|
+
- ".github/workflows/ci.yml"
|
|
97
|
+
- ".gitignore"
|
|
98
|
+
- ".rspec"
|
|
99
|
+
- ".rubocop.yml"
|
|
100
|
+
- ".travis.yml"
|
|
101
|
+
- CHANGELOG.md
|
|
102
|
+
- Gemfile
|
|
103
|
+
- LICENSE
|
|
104
|
+
- README.md
|
|
105
|
+
- Rakefile
|
|
106
|
+
- bin/console
|
|
107
|
+
- bin/setup
|
|
108
|
+
- googleauth-extras.gemspec
|
|
109
|
+
- lib/google/auth/extras.rb
|
|
110
|
+
- lib/google/auth/extras/impersonated_credential.rb
|
|
111
|
+
- lib/google/auth/extras/static_credential.rb
|
|
112
|
+
- lib/google/auth/extras/token_info.rb
|
|
113
|
+
- lib/google/auth/extras/version.rb
|
|
114
|
+
- lib/googleauth/extras.rb
|
|
115
|
+
homepage: https://github.com/persona-id/googleauth-extras
|
|
116
|
+
licenses:
|
|
117
|
+
- MIT
|
|
118
|
+
metadata:
|
|
119
|
+
allowed_push_host: https://rubygems.org
|
|
120
|
+
rubygems_mfa_required: 'true'
|
|
121
|
+
homepage_uri: https://github.com/persona-id/googleauth-extras
|
|
122
|
+
source_code_uri: https://github.com/persona-id/googleauth-extras
|
|
123
|
+
changelog_uri: https://github.com/persona-id/googleauth-extras/blob/main/CHANGELOG.md
|
|
124
|
+
post_install_message:
|
|
125
|
+
rdoc_options: []
|
|
126
|
+
require_paths:
|
|
127
|
+
- lib
|
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
|
+
requirements:
|
|
130
|
+
- - ">="
|
|
131
|
+
- !ruby/object:Gem::Version
|
|
132
|
+
version: 2.7.0
|
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
requirements: []
|
|
139
|
+
rubygems_version: 3.1.6
|
|
140
|
+
signing_key:
|
|
141
|
+
specification_version: 4
|
|
142
|
+
summary: Additions to the googleauth gem for unsupported authentication schemes.
|
|
143
|
+
test_files: []
|