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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7de14445c693279f09a86e7e1cd7c349c492b30a532b0951d49aed52eec90a96
4
- data.tar.gz: b9d44e07749d0e017430f7614d6250ad1370f185839a0ed778573d39a6046e25
3
+ metadata.gz: 3be0a29d282ba73edc1e0b3c7816cf53b9c335b3c46f10b30b3b7a731ec0b584
4
+ data.tar.gz: 0b7440d8f9bdcfb1c59ddcb11526120db6cdcd773c5f8a4d71bb0bde49fe5c20
5
5
  SHA512:
6
- metadata.gz: c10995031a23f2b0ee9b4fe6f6e5dbced77fe1fdcd9575d61f59de493a3d4b3190abff8212134e125d6e0bdb6cdc118e7a584141312372c0faa6aa8ef63b956f
7
- data.tar.gz: 0db53d013d400c848debb9b5f38092128a8704d199947af608215a911d12bbf5586a945db23509c31692d1f4b232d22ec67afea1a4076e0fbe04f5c99006301f
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
- Auth as an application installation for a repo and return an Octokit::Client.
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 = app_installation_client("myaccount/myrepo")
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 = app_instalation_token("myaccount/myrepo")
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
- application_client = app_client
10
- installation = application_client.find_repository_installation(repo)
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
@@ -1,7 +1,7 @@
1
1
  module GitHub
2
2
  module App
3
3
  module Auth
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -5,6 +5,10 @@ require "github-app-auth/version"
5
5
  module GitHub
6
6
  module App
7
7
  module Auth
8
+ class Error < StandardError; end
9
+ class InstallationError < Error; end
10
+ class TokenError< Error; end
11
+
8
12
  class AuthClass
9
13
  include GitHub::App::Auth
10
14
  end
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.2.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-05 00:00:00.000000000 Z
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