github-app-auth 0.3.0 → 0.4.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/CHANGELOG.md +4 -0
- data/README.md +6 -3
- data/lib/{github-app-auth → github_app_auth}/app.rb +6 -11
- data/lib/{github-app-auth → github_app_auth}/app_installation.rb +23 -24
- data/lib/{github-app-auth → github_app_auth}/client.rb +3 -0
- data/lib/{github-app-auth → github_app_auth}/version.rb +3 -1
- data/lib/{github-app-auth.rb → github_app_auth.rb} +7 -4
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dfa01cb297c9e23c8f0342a92500065145151061ccf3d5ccc0c9a88f6882500
|
4
|
+
data.tar.gz: 4e320ac747cde80c1734b40d67463be810beadb303d08ed87ce35f461f1c6f0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb5af34f92a868bdfe6276e19784ae2f8366bee7df538e38aa279558f1038510485a295b714a266b9cc11f778968507316214c276565e3fc9c46b51cdee20015
|
7
|
+
data.tar.gz: 7c203243829d4d54557616f0d514f0ac4da37aff788846d6bfcc89253e4013a16ef6bad1710bf75441dfa7138e061a9a8a4274a92c3bca1f5cca3f12841e32f3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.4.0
|
4
|
+
- remove deprecated app_* methods that were only repository installations
|
5
|
+
- change require to 'github_app_auth' when adding linter
|
6
|
+
|
3
7
|
## 0.3.0
|
4
8
|
- deprecates app_* methods that were only repository installations
|
5
9
|
- adds methods to do organization, repository, and user installations
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# GitHub::App::Auth
|
2
2
|
|
3
|
+

|
4
|
+
[](https://badge.fury.io/rb/github-app-auth)
|
5
|
+
|
3
6
|
A gem to make (at least) some forms of GitHub App authentication easy. It is built as an includable module, with the option of a class to
|
4
7
|
instantiate if preferred.
|
5
8
|
|
@@ -22,7 +25,7 @@ Or install it yourself as:
|
|
22
25
|
## Usage
|
23
26
|
|
24
27
|
```
|
25
|
-
require "
|
28
|
+
require "github_app_auth"
|
26
29
|
```
|
27
30
|
|
28
31
|
Include the module in your class
|
@@ -99,12 +102,12 @@ client = Octokit::Client.new({ bearer_token: token, ... })
|
|
99
102
|
|
100
103
|
Auth as an application installation for a user and return an Octokit::Client.
|
101
104
|
```
|
102
|
-
client = user_installation_client("
|
105
|
+
client = user_installation_client("myuser")
|
103
106
|
```
|
104
107
|
|
105
108
|
Alternatively you can retrieve the token, and then set up your own GitHub client (Octokit or whatever you prefer) as needed.
|
106
109
|
```
|
107
|
-
token = user_installation_token("
|
110
|
+
token = user_installation_token("myuser")
|
108
111
|
client = Octokit::Client.new({ bearer_token: token, ... })
|
109
112
|
```
|
110
113
|
|
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "jwt"
|
2
4
|
require "openssl"
|
3
5
|
require_relative "client"
|
4
6
|
|
5
7
|
module GitHub
|
6
8
|
module App
|
9
|
+
# GitHub App Authentication
|
7
10
|
module Auth
|
8
11
|
def app_client(options = {})
|
9
|
-
client(:
|
12
|
+
client(bearer_token: app_token(options))
|
10
13
|
end
|
11
14
|
|
12
15
|
# options: the following can be passed via the options hash. if missing
|
@@ -32,19 +35,11 @@ module GitHub
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def app_id(options = {})
|
35
|
-
|
36
|
-
options[:github_app_id]
|
37
|
-
else
|
38
|
-
ENV["GITHUB_APP_ID"]
|
39
|
-
end
|
38
|
+
options[:github_app_id] || ENV["GITHUB_APP_ID"]
|
40
39
|
end
|
41
40
|
|
42
41
|
def app_private_key(options = {})
|
43
|
-
|
44
|
-
options[:github_app_private_key]
|
45
|
-
else
|
46
|
-
ENV["GITHUB_APP_PRIVATE_KEY"]
|
47
|
-
end
|
42
|
+
options[:github_app_private_key] || ENV["GITHUB_APP_PRIVATE_KEY"]
|
48
43
|
end
|
49
44
|
end
|
50
45
|
end
|
@@ -1,17 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GitHub
|
2
4
|
module App
|
5
|
+
# GitHub App Installation Authentication
|
3
6
|
module Auth
|
4
|
-
# legacy support because original only supported repo
|
5
|
-
def app_installation_client(repo, options = {})
|
6
|
-
puts "DEPRECATED: app_installation_client will be removed in v0.4.0, use repository_installation_client instead"
|
7
|
-
client(bearer_token: app_installation_token(repo, options))
|
8
|
-
end
|
9
|
-
|
10
|
-
def app_installation_token(repo, options = {})
|
11
|
-
puts "DEPRECATED: app_installation_token will be removed in v0.4.0, use repository_installation_token instead"
|
12
|
-
installation_token(:repository, repo, options)
|
13
|
-
end
|
14
|
-
|
15
7
|
def organization_installation_client(org, options = {})
|
16
8
|
client(bearer_token: organization_installation_token(org, options))
|
17
9
|
end
|
@@ -38,19 +30,8 @@ module GitHub
|
|
38
30
|
|
39
31
|
# Supported types are :organization, :repository, :user
|
40
32
|
def installation_token(type, name, options = {})
|
41
|
-
application_client
|
42
|
-
installation =
|
43
|
-
case type
|
44
|
-
when :organization
|
45
|
-
application_client.find_organization_installation(name)
|
46
|
-
when :repository
|
47
|
-
application_client.find_repository_installation(name)
|
48
|
-
when :user
|
49
|
-
application_client.find_user_installation(name)
|
50
|
-
else
|
51
|
-
raise ArgumentError, "Unsupported installation type: #{type}"
|
52
|
-
end
|
53
|
-
end
|
33
|
+
application_client(options)
|
34
|
+
installation = installation_by_type(type, name)
|
54
35
|
|
55
36
|
if installation.nil? || installation[:id].nil?
|
56
37
|
raise GitHub::App::Auth::InstallationError, "Could not find installation for #{type}: #{name}"
|
@@ -60,8 +41,26 @@ module GitHub
|
|
60
41
|
if resp.nil? || resp[:token].nil?
|
61
42
|
raise GitHub::App::Auth::TokenError, "Could generate installation token for #{type}: #{name}"
|
62
43
|
end
|
44
|
+
|
63
45
|
resp[:token]
|
64
46
|
end
|
47
|
+
|
48
|
+
def installation_by_type(type, name)
|
49
|
+
case type
|
50
|
+
when :organization
|
51
|
+
application_client.find_organization_installation(name)
|
52
|
+
when :repository
|
53
|
+
application_client.find_repository_installation(name)
|
54
|
+
when :user
|
55
|
+
application_client.find_user_installation(name)
|
56
|
+
else
|
57
|
+
raise ArgumentError, "Unsupported installation type: #{type}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def application_client(options = {})
|
62
|
+
@application_client ||= app_client(options)
|
63
|
+
end
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
@@ -1,13 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "github_app_auth/app"
|
4
|
+
require "github_app_auth/app_installation"
|
5
|
+
require "github_app_auth/version"
|
4
6
|
|
5
7
|
module GitHub
|
6
8
|
module App
|
9
|
+
# GitHub App Authentication
|
7
10
|
module Auth
|
8
11
|
class Error < StandardError; end
|
9
12
|
class InstallationError < Error; end
|
10
|
-
class TokenError< Error; end
|
13
|
+
class TokenError < Error; end
|
11
14
|
|
12
15
|
class AuthClass
|
13
16
|
include GitHub::App::Auth
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-app-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Horton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -63,11 +63,11 @@ files:
|
|
63
63
|
- CODE_OF_CONDUCT.md
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
|
-
- lib/
|
67
|
-
- lib/
|
68
|
-
- lib/
|
69
|
-
- lib/
|
70
|
-
- lib/
|
66
|
+
- lib/github_app_auth.rb
|
67
|
+
- lib/github_app_auth/app.rb
|
68
|
+
- lib/github_app_auth/app_installation.rb
|
69
|
+
- lib/github_app_auth/client.rb
|
70
|
+
- lib/github_app_auth/version.rb
|
71
71
|
homepage: https://github.com/hortoncd/github-app-auth
|
72
72
|
licenses:
|
73
73
|
- MIT
|
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
requirements:
|
84
84
|
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
86
|
+
version: 3.0.0
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
89
|
- - ">="
|