github-app-auth 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -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 +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3affc8985250914b5ba01494501ea5f533c20da2c521dc23132a2c443e2d23a2
|
4
|
+
data.tar.gz: 8b744664086d292747ec98d48f4939553bb4aa6a4f14f26cba550214e0620b4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f3ddd10c6665f938b7a395d9a357dfd1852e050ff09ccd71d087783d16d84376484eb944a18b43c288ac24e2f4daa1accdee3feadea335147635181a66961f0
|
7
|
+
data.tar.gz: 94b912f22dfce7113481f62385d94ebe8c980af271bb036727e8c6b9ead49fedd69d63cf19487240af366691b81e6267651a717d51a01c585701a15c1e6f4b47
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.4.1
|
4
|
+
- loosen restriction on Octokit version
|
5
|
+
|
6
|
+
## 0.4.0
|
7
|
+
- remove deprecated app_* methods that were only repository installations
|
8
|
+
- change require to 'github_app_auth' when adding linter
|
9
|
+
|
3
10
|
## 0.3.0
|
4
11
|
- deprecates app_* methods that were only repository installations
|
5
12
|
- 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
|
+
![Tests](https://github.com/hortoncd/github-app-auth/actions/workflows/tests.yml/badge.svg)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/github-app-auth.svg)](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.1
|
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-
|
11
|
+
date: 2023-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: octokit
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '6.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '6.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -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
|
- - ">="
|