github-authentication 1.2.0 → 1.3.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 +4 -4
- data/.github/workflows/tests.yml +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +56 -44
- data/README.md +25 -53
- data/exe/git-credential-github-app +2 -5
- data/lib/github_authentication/git_credential_helper.rb +3 -21
- data/lib/github_authentication/version.rb +1 -1
- data/lib/github_authentication.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 516354d28c957aa1fe159319fe2c6ae1db1dbc50e3493a14b364f6c08526fc5a
|
|
4
|
+
data.tar.gz: 77810176f1496cef5171bbc279e0545d3a8624b268ef07f27a0ab3468a833d8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4bfaf85cdcb8a3c4c98369cea4ddb1bbea55a9ce1b4099529dbc898b2da80d158d8b82fc456088ad49575b4fe7c5183c3969fb5fbc40ad734e01a23af9f0ea6e
|
|
7
|
+
data.tar.gz: 87be1a5c672e5a02f55bb2665464e9df08efe1d1c79af56d2f0ef3d230229552af4770f0576a3ff9f3732a16de0e84be4b74b7c048212a72df66c00872f3a2ee
|
data/.github/workflows/tests.yml
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4.0.1
|
data/CHANGELOG.md
CHANGED
|
@@ -2,5 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
...
|
|
4
4
|
|
|
5
|
+
### 1.3.0
|
|
6
|
+
- Add `GithubAuthentication.provider(org:, env:)` as a high-level entrypoint for Ruby code that needs GitHub App tokens without manually wiring up Environment, Generator, Cache, and Provider
|
|
7
|
+
- Simplify `GitCredentialHelper` to accept a `provider` directly
|
|
8
|
+
- Update test runners to test against more recent Ruby versions
|
|
9
|
+
|
|
5
10
|
### 1.2.0
|
|
6
11
|
- Support multi-org credentials (https://github.com/Shopify/github-authentication/pull/34)
|
data/Gemfile.lock
CHANGED
|
@@ -1,76 +1,87 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
github-authentication (1.
|
|
4
|
+
github-authentication (1.3.0)
|
|
5
5
|
jwt (~> 2.2)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
activesupport (
|
|
10
|
+
activesupport (8.1.2)
|
|
11
11
|
base64
|
|
12
12
|
bigdecimal
|
|
13
|
-
concurrent-ruby (~> 1.0, >= 1.
|
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
14
14
|
connection_pool (>= 2.2.5)
|
|
15
15
|
drb
|
|
16
16
|
i18n (>= 1.6, < 2)
|
|
17
|
+
json
|
|
18
|
+
logger (>= 1.4.2)
|
|
17
19
|
minitest (>= 5.1)
|
|
18
|
-
|
|
19
|
-
tzinfo (~> 2.0)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
securerandom (>= 0.3)
|
|
21
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
|
22
|
+
uri (>= 0.13.1)
|
|
23
|
+
addressable (2.8.8)
|
|
24
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
25
|
+
ast (2.4.3)
|
|
26
|
+
base64 (0.3.0)
|
|
27
|
+
bigdecimal (4.0.1)
|
|
28
|
+
concurrent-ruby (1.3.6)
|
|
29
|
+
connection_pool (3.0.2)
|
|
30
|
+
crack (1.0.1)
|
|
31
|
+
bigdecimal
|
|
28
32
|
rexml
|
|
29
|
-
drb (2.2.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
i18n (1.14.1)
|
|
33
|
+
drb (2.2.3)
|
|
34
|
+
hashdiff (1.2.1)
|
|
35
|
+
i18n (1.14.8)
|
|
33
36
|
concurrent-ruby (~> 1.0)
|
|
34
|
-
json (2.
|
|
35
|
-
jwt (2.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
json (2.18.1)
|
|
38
|
+
jwt (2.10.2)
|
|
39
|
+
base64
|
|
40
|
+
language_server-protocol (3.17.0.5)
|
|
41
|
+
lint_roller (1.1.0)
|
|
42
|
+
logger (1.7.0)
|
|
43
|
+
minitest (5.27.0)
|
|
44
|
+
mocha (2.8.2)
|
|
39
45
|
ruby2_keywords (>= 0.0.5)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
parser (3.3.0.5)
|
|
46
|
+
parallel (1.27.0)
|
|
47
|
+
parser (3.3.10.1)
|
|
43
48
|
ast (~> 2.4.1)
|
|
44
49
|
racc
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
prism (1.9.0)
|
|
51
|
+
public_suffix (7.0.2)
|
|
52
|
+
racc (1.8.1)
|
|
47
53
|
rainbow (3.1.1)
|
|
48
|
-
rake (13.1
|
|
49
|
-
regexp_parser (2.
|
|
50
|
-
rexml (3.
|
|
51
|
-
rubocop (1.
|
|
54
|
+
rake (13.3.1)
|
|
55
|
+
regexp_parser (2.11.3)
|
|
56
|
+
rexml (3.4.4)
|
|
57
|
+
rubocop (1.84.2)
|
|
52
58
|
json (~> 2.3)
|
|
53
|
-
language_server-protocol (
|
|
59
|
+
language_server-protocol (~> 3.17.0.2)
|
|
60
|
+
lint_roller (~> 1.1.0)
|
|
54
61
|
parallel (~> 1.10)
|
|
55
62
|
parser (>= 3.3.0.2)
|
|
56
63
|
rainbow (>= 2.2.2, < 4.0)
|
|
57
|
-
regexp_parser (>=
|
|
58
|
-
|
|
59
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
|
64
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
65
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
60
66
|
ruby-progressbar (~> 1.7)
|
|
61
|
-
unicode-display_width (>= 2.4.0, <
|
|
62
|
-
rubocop-ast (1.
|
|
63
|
-
parser (>= 3.3.
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
68
|
+
rubocop-ast (1.49.0)
|
|
69
|
+
parser (>= 3.3.7.2)
|
|
70
|
+
prism (~> 1.7)
|
|
71
|
+
rubocop-shopify (2.18.0)
|
|
72
|
+
rubocop (~> 1.62)
|
|
66
73
|
ruby-progressbar (1.13.0)
|
|
67
74
|
ruby2_keywords (0.0.5)
|
|
68
|
-
|
|
75
|
+
securerandom (0.4.1)
|
|
76
|
+
timecop (0.9.10)
|
|
69
77
|
tzinfo (2.0.6)
|
|
70
78
|
concurrent-ruby (~> 1.0)
|
|
71
|
-
unicode-display_width (2.
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
unicode-display_width (3.2.0)
|
|
80
|
+
unicode-emoji (~> 4.1)
|
|
81
|
+
unicode-emoji (4.2.0)
|
|
82
|
+
uri (1.1.1)
|
|
83
|
+
vcr (6.4.0)
|
|
84
|
+
webmock (3.26.1)
|
|
74
85
|
addressable (>= 2.8.0)
|
|
75
86
|
crack (>= 0.3.2)
|
|
76
87
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
@@ -79,6 +90,7 @@ PLATFORMS
|
|
|
79
90
|
arm64-darwin-21
|
|
80
91
|
arm64-darwin-22
|
|
81
92
|
arm64-darwin-23
|
|
93
|
+
arm64-darwin-24
|
|
82
94
|
x86_64-linux
|
|
83
95
|
|
|
84
96
|
DEPENDENCIES
|
data/README.md
CHANGED
|
@@ -22,32 +22,43 @@ Or install it yourself as:
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
+
The simplest way to get a GitHub App token is via `GithubAuthentication.provider`, which reads credentials from environment variables, handles JWT generation, token exchange, and caching:
|
|
26
|
+
|
|
25
27
|
```ruby
|
|
26
28
|
require 'github-authentication'
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
installation_id: ENV['GITHUB_INSTALLATION_ID'],
|
|
31
|
-
app_id: ENV['GITHUB_APP_ID'])
|
|
32
|
-
provider = GithubAuthentication::Provider.new(generator: generator, cache: cache)
|
|
33
|
-
|
|
34
|
-
provider.token
|
|
35
|
-
provider.reset_token
|
|
30
|
+
provider = GithubAuthentication.provider(org: "myorg")
|
|
31
|
+
provider.token # => returns a cached or freshly generated token
|
|
36
32
|
```
|
|
37
33
|
|
|
38
|
-
|
|
34
|
+
This expects the following environment variables to be set (optionally prefixed with the org name):
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
`
|
|
36
|
+
- `GITHUB_APP_ID` (or `MYORG_GITHUB_APP_ID`)
|
|
37
|
+
- `GITHUB_APP_INSTALLATION_ID` (or `MYORG_GITHUB_APP_INSTALLATION_ID`)
|
|
38
|
+
- `GITHUB_APP_KEYFILE` (or `MYORG_GITHUB_APP_KEYFILE`)
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
If `GITHUB_APP_CREDENTIAL_STORAGE_PATH` is set, tokens are cached to disk via `ActiveSupport::Cache::FileStore`. Otherwise an in-memory cache is used.
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
### Using with Octokit
|
|
46
43
|
|
|
47
44
|
```ruby
|
|
48
|
-
GithubAuthentication
|
|
45
|
+
provider = GithubAuthentication.provider(org: "myorg")
|
|
46
|
+
client = Octokit::Client.new(access_token: provider.token.to_s)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Building a provider manually
|
|
50
|
+
|
|
51
|
+
If you need more control over the cache or generator, you can wire up the components yourself:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
cache = GithubAuthentication::Cache.new(storage: GithubAuthentication::ObjectCache.new)
|
|
55
|
+
generator = GithubAuthentication::Generator::App.new(pem: ENV['GITHUB_PEM'],
|
|
49
56
|
installation_id: ENV['GITHUB_INSTALLATION_ID'],
|
|
50
57
|
app_id: ENV['GITHUB_APP_ID'])
|
|
58
|
+
provider = GithubAuthentication::Provider.new(generator: generator, cache: cache)
|
|
59
|
+
|
|
60
|
+
provider.token
|
|
61
|
+
provider.reset_token
|
|
51
62
|
```
|
|
52
63
|
|
|
53
64
|
### Generator::Personal
|
|
@@ -57,45 +68,6 @@ Mostly for testing purposes you can provide a github token that gets retrieved.
|
|
|
57
68
|
GithubAuthentication::Generator::Personal.new(github_token: ENV['GITHUB_TOKEN'])
|
|
58
69
|
```
|
|
59
70
|
|
|
60
|
-
## Example
|
|
61
|
-
|
|
62
|
-
```ruby
|
|
63
|
-
|
|
64
|
-
require "base64"
|
|
65
|
-
|
|
66
|
-
module GitHub
|
|
67
|
-
APP_ID = "<APP_ID>"
|
|
68
|
-
INSTALLATION_ID = "<INSTALLATION_ID>"
|
|
69
|
-
|
|
70
|
-
class << self
|
|
71
|
-
def token
|
|
72
|
-
@token_provider ||= begin
|
|
73
|
-
if ENV['GITHUB_TOKEN']
|
|
74
|
-
storage = GithubAuthentication::ObjectCache.new
|
|
75
|
-
generator = GithubAuthentication::Generator::Personal.new(github_token: ENV['GITHUB_TOKEN'])
|
|
76
|
-
else
|
|
77
|
-
storage = ActiveSupport::Cache::RedisCacheStore.new
|
|
78
|
-
pem = Base64.decode64(ENV['GITHUB_PEM'])
|
|
79
|
-
generator = GithubAuthentication::Generator::App.new(pem: pem, installation_id: INSTALLATION_ID,
|
|
80
|
-
app_id: APP_ID)
|
|
81
|
-
end
|
|
82
|
-
cache = GithubAuthentication::Cache.new(storage: storage)
|
|
83
|
-
GithubAuthentication::Provider.new(generator: generator, cache: cache)
|
|
84
|
-
end
|
|
85
|
-
@token_provider.token
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def client
|
|
89
|
-
if ENV['GITHUB_TOKEN']
|
|
90
|
-
Octokit::Client.new(access_token: token.to_s)
|
|
91
|
-
else
|
|
92
|
-
Octokit::Client.new(bearer_token: token.to_s)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
```
|
|
98
|
-
|
|
99
71
|
## Git credential helper
|
|
100
72
|
|
|
101
73
|
This gem also ships with a [git credential helper][0] to authenticate git
|
|
@@ -16,13 +16,10 @@ case ARGV[0]
|
|
|
16
16
|
when "get"
|
|
17
17
|
description = $stdin.each_line.map { |line| line.split("=", 2).map(&:strip) }.to_h
|
|
18
18
|
org = description.fetch("path", "").split("/").first
|
|
19
|
-
|
|
19
|
+
provider = GithubAuthentication.provider(org: org)
|
|
20
20
|
|
|
21
21
|
exit_status = GithubAuthentication::GitCredentialHelper.new(
|
|
22
|
-
|
|
23
|
-
app_id: environment.app_id,
|
|
24
|
-
installation_id: environment.installation_id,
|
|
25
|
-
storage: environment.storage,
|
|
22
|
+
provider: provider,
|
|
26
23
|
description: description,
|
|
27
24
|
).handle_get
|
|
28
25
|
exit(exit_status)
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module GithubAuthentication
|
|
4
4
|
class GitCredentialHelper
|
|
5
|
-
def initialize(
|
|
6
|
-
@
|
|
7
|
-
@installation_id = installation_id
|
|
8
|
-
@app_id = app_id
|
|
5
|
+
def initialize(provider:, description:)
|
|
6
|
+
@provider = provider
|
|
9
7
|
@description = description
|
|
10
|
-
@storage = storage
|
|
11
8
|
end
|
|
12
9
|
|
|
13
10
|
def handle_get
|
|
@@ -16,7 +13,7 @@ module GithubAuthentication
|
|
|
16
13
|
return 2
|
|
17
14
|
end
|
|
18
15
|
|
|
19
|
-
token = provider.token(seconds_ttl: min_cache_ttl)
|
|
16
|
+
token = @provider.token(seconds_ttl: min_cache_ttl)
|
|
20
17
|
puts("password=#{token}")
|
|
21
18
|
puts("username=api")
|
|
22
19
|
|
|
@@ -29,20 +26,5 @@ module GithubAuthentication
|
|
|
29
26
|
# Tokens are valid for 60 minutes, allow a 10 minute buffer
|
|
30
27
|
10 * 60
|
|
31
28
|
end
|
|
32
|
-
|
|
33
|
-
def provider
|
|
34
|
-
@provider ||= Provider.new(
|
|
35
|
-
generator: generator,
|
|
36
|
-
cache: Cache.new(storage: @storage || ObjectCache.new),
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def generator
|
|
41
|
-
@generator ||= Generator::App.new(
|
|
42
|
-
pem: @pem,
|
|
43
|
-
app_id: @app_id,
|
|
44
|
-
installation_id: @installation_id,
|
|
45
|
-
)
|
|
46
|
-
end
|
|
47
29
|
end
|
|
48
30
|
end
|
|
@@ -9,4 +9,21 @@ require "github_authentication/object_cache"
|
|
|
9
9
|
require "github_authentication/git_credential_helper"
|
|
10
10
|
|
|
11
11
|
module GithubAuthentication
|
|
12
|
+
class << self
|
|
13
|
+
def provider(org:, env: ENV)
|
|
14
|
+
ga_env = Environment.new(org: org, env: env)
|
|
15
|
+
generator = Generator::App.new(
|
|
16
|
+
pem: ga_env.pem,
|
|
17
|
+
installation_id: ga_env.installation_id,
|
|
18
|
+
app_id: ga_env.app_id,
|
|
19
|
+
)
|
|
20
|
+
storage = begin
|
|
21
|
+
ga_env.storage
|
|
22
|
+
rescue KeyError
|
|
23
|
+
ObjectCache.new
|
|
24
|
+
end
|
|
25
|
+
cache = Cache.new(storage: storage, key: org)
|
|
26
|
+
Provider.new(generator: generator, cache: cache)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
12
29
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: github-authentication
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Frederik Dudzik
|
|
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
195
195
|
- !ruby/object:Gem::Version
|
|
196
196
|
version: '0'
|
|
197
197
|
requirements: []
|
|
198
|
-
rubygems_version:
|
|
198
|
+
rubygems_version: 4.0.6
|
|
199
199
|
specification_version: 4
|
|
200
200
|
summary: GitHub Authetication
|
|
201
201
|
test_files: []
|