github-app-auth 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 +11 -0
- data/README.md +33 -3
- data/lib/github-app-auth/app_installation.rb +53 -2
- data/lib/github-app-auth/version.rb +1 -1
- data/lib/github-app-auth.rb +4 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3be0a29d282ba73edc1e0b3c7816cf53b9c335b3c46f10b30b3b7a731ec0b584
|
4
|
+
data.tar.gz: 0b7440d8f9bdcfb1c59ddcb11526120db6cdcd773c5f8a4d71bb0bde49fe5c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3c04c0f3b7e4c5089cdf9a2ab970ce9ccb74636f32590b0f2465e2b1408575630c3c2e606bfe193e8520c15d35e388ce1ca420a978578670f1f5faa44f92ede
|
7
|
+
data.tar.gz: 0b34fca8d227fa565563efad2abb2a2c5f8245ddfdb091a5f4eb4089f9c70e5ab6a5f07525ca49a277c9ef0a5922937162fd4ce9f6ce1297446cc3a06b5df347
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.3.0
|
4
|
+
- deprecates app_* methods that were only repository installations
|
5
|
+
- adds methods to do organization, repository, and user installations
|
6
|
+
|
7
|
+
## 0.2.0
|
8
|
+
- changed lib path to `github-app-auth` instead of `github/app/auth`
|
9
|
+
|
10
|
+
## 0.1.0
|
11
|
+
- initial release with support for repository installation authentication
|
data/README.md
CHANGED
@@ -67,14 +67,44 @@ See [the GitHub documentation](https://docs.github.com/en/apps/creating-github-a
|
|
67
67
|
|
68
68
|
The examples are using the gem as an includable module, but can also be used with the available AuthClass class..
|
69
69
|
|
70
|
-
|
70
|
+
There are several methods of authenticating as an application installation.
|
71
|
+
|
72
|
+
#### Organization Installation
|
73
|
+
|
74
|
+
Auth as an application installation for an organization and return an Octokit::Client.
|
75
|
+
```
|
76
|
+
client = organization_installation_client("myorg")
|
77
|
+
```
|
78
|
+
|
79
|
+
Alternatively you can retrieve the token, and then set up your own GitHub client (Octokit or whatever you prefer) as needed.
|
80
|
+
```
|
81
|
+
token = organization_installation_token("myorg")
|
82
|
+
client = Octokit::Client.new({ bearer_token: token, ... })
|
83
|
+
```
|
84
|
+
|
85
|
+
#### Repository Installation
|
86
|
+
|
87
|
+
Auth as an application installation for a repository and return an Octokit::Client.
|
88
|
+
```
|
89
|
+
client = repository_installation_client("myaccount/myrepo")
|
90
|
+
```
|
91
|
+
|
92
|
+
Alternatively you can retrieve the token, and then set up your own GitHub client (Octokit or whatever you prefer) as needed.
|
93
|
+
```
|
94
|
+
token = repository_installation_token("myaccount/myrepo")
|
95
|
+
client = Octokit::Client.new({ bearer_token: token, ... })
|
96
|
+
```
|
97
|
+
|
98
|
+
#### User Installation
|
99
|
+
|
100
|
+
Auth as an application installation for a user and return an Octokit::Client.
|
71
101
|
```
|
72
|
-
client =
|
102
|
+
client = user_installation_client("myorg")
|
73
103
|
```
|
74
104
|
|
75
105
|
Alternatively you can retrieve the token, and then set up your own GitHub client (Octokit or whatever you prefer) as needed.
|
76
106
|
```
|
77
|
-
token =
|
107
|
+
token = user_installation_token("myorg")
|
78
108
|
client = Octokit::Client.new({ bearer_token: token, ... })
|
79
109
|
```
|
80
110
|
|
@@ -1,14 +1,65 @@
|
|
1
1
|
module GitHub
|
2
2
|
module App
|
3
3
|
module Auth
|
4
|
+
# legacy support because original only supported repo
|
4
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"
|
5
7
|
client(bearer_token: app_installation_token(repo, options))
|
6
8
|
end
|
7
9
|
|
8
10
|
def app_installation_token(repo, options = {})
|
9
|
-
|
10
|
-
|
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
|
+
def organization_installation_client(org, options = {})
|
16
|
+
client(bearer_token: organization_installation_token(org, options))
|
17
|
+
end
|
18
|
+
|
19
|
+
def organization_installation_token(org, options = {})
|
20
|
+
installation_token(:organization, org, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def repository_installation_client(repo, options = {})
|
24
|
+
client(bearer_token: repository_installation_token(repo, options))
|
25
|
+
end
|
26
|
+
|
27
|
+
def repository_installation_token(repo, options = {})
|
28
|
+
installation_token(:repository, repo, options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def user_installation_client(user, options = {})
|
32
|
+
client(bearer_token: user_installation_token(user, options))
|
33
|
+
end
|
34
|
+
|
35
|
+
def user_installation_token(user, options = {})
|
36
|
+
installation_token(:user, user, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Supported types are :organization, :repository, :user
|
40
|
+
def installation_token(type, name, options = {})
|
41
|
+
application_client = app_client(options)
|
42
|
+
installation = begin
|
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
|
54
|
+
|
55
|
+
if installation.nil? || installation[:id].nil?
|
56
|
+
raise GitHub::App::Auth::InstallationError, "Could not find installation for #{type}: #{name}"
|
57
|
+
end
|
58
|
+
|
11
59
|
resp = application_client.create_app_installation_access_token(installation[:id])
|
60
|
+
if resp.nil? || resp[:token].nil?
|
61
|
+
raise GitHub::App::Auth::TokenError, "Could generate installation token for #{type}: #{name}"
|
62
|
+
end
|
12
63
|
resp[:token]
|
13
64
|
end
|
14
65
|
end
|
data/lib/github-app-auth.rb
CHANGED
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.3.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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- CHANGELOG.md
|
62
63
|
- CODE_OF_CONDUCT.md
|
63
64
|
- LICENSE.txt
|
64
65
|
- README.md
|