exoauth 0.1.0 → 0.1.2

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: '0417275861e8def76ab9f53cc0e62c74670dcb790c4dd8b695e7debbc3613fbe'
4
- data.tar.gz: c1827f16b9a16293079ae609f2f451dd4f7957a4b4740777aacd5299df9b1c31
3
+ metadata.gz: 6413f8e41e505e8c5a9c53c019ff3f332bedaf0e036894b8dd84ba389eb73613
4
+ data.tar.gz: 8c489d53f0b37a7b76a28b84bce26543f9db2e2e09305e2f7fdfc615282b7f4d
5
5
  SHA512:
6
- metadata.gz: 3c89974b8622adbab518a1b5a76c8a87f17a25b8da419347234433d1884cc866aa57f26ee1988913a29a5055c992b8cb06f07b1c390b83322b76652b047932e1
7
- data.tar.gz: 2e8a34be42eb834f0ba76b42b9e5c5a19ffe41549576bdafac5a87366764263cbd7f989e0f90d9950410ba50f24f80dc9da81fcd52821c21dff87b892a5c0977
6
+ metadata.gz: 2207012fd67629753bab89a4daadfe9281b7cd86ea9e90446a8b81a83e91a4ad45210656c79e4bdc512ede84e1464d46d660e0ea0a4fc6fca62381dfed9c7eb1
7
+ data.tar.gz: 5918f7541a30e9fe82826c3c5a47b858b1c43b88092c3ebe1e7e88d8f9a744a4c4e2cd6bac046c4563cd3180d2e96c8d3c4485095cb8d5c01171b873371da641
data/README.md CHANGED
@@ -11,7 +11,15 @@ AuthHelpers: This gem provides auth helpers for a Ruby project.
11
11
 
12
12
  ## Getting started
13
13
 
14
+ `bundle`
15
+
16
+ `rake build`
17
+
18
+ `gem push [GEM.gem]`
19
+
20
+
14
21
  ### Requirements
15
22
 
16
23
  - Ruby 2.5+
17
24
  - JWT 2.3.0
25
+ - ExoBasic 0.1.0
data/lib/exoauth/auth.rb CHANGED
@@ -97,6 +97,26 @@ module ExoAuth
97
97
  pub_key
98
98
  end
99
99
 
100
+ def self.key_from_string(str, algorithm)
101
+ key = nil
102
+ case algorithm
103
+ when 'HS256'
104
+ key = str
105
+ when 'ES384', 'ES512', 'RS256'
106
+ key = OpenSSL::PKey.read(str)
107
+ end
108
+
109
+ key
110
+ end
111
+
112
+ def self.key_from_env(varname, algorithm)
113
+ Auth.key_from_string(ENV[varname], algorithm)
114
+ end
115
+
116
+ def self.key_from_settings(field, algorithm)
117
+ Auth.key_from_string(@@conf[field], algorithm)
118
+ end
119
+
100
120
  def self.key_from_file(fname, algorithm)
101
121
  key = nil
102
122
  File.open(fname) do |file|
@@ -175,60 +195,38 @@ module ExoAuth
175
195
  payload
176
196
  end
177
197
  rescue JWT::DecodeError => e
178
- return false
198
+ false
179
199
  end
180
200
  end
181
201
 
182
- @@app_signing_key = ExoBasic::Settings.try_get_key(@@conf,
183
- true,
184
- 'signing_enabled') ?
185
- Auth.key_from_file(
186
- File.expand_path(
187
- ExoBasic::Settings.try_get_key(@@conf,
188
- Auth::DEFAULT_SIGNING_KEY_PATH,
189
- 'signing_key_path'),
190
- __FILE__),
191
- Auth.app_algorithm) :
192
- nil
193
-
194
- @@app_verify_key = ExoBasic::Settings.try_get_key(@@conf,
195
- true,
196
- 'verify_enabled') ?
197
- Auth.key_from_file(
198
- File.expand_path(
199
- ExoBasic::Settings.try_get_key(@@conf,
200
- Auth::DEFAULT_VERIFY_KEY_PATH,
201
- 'verify_key_path'),
202
- __FILE__),
203
- Auth.app_algorithm) :
204
- nil
202
+ def self.init_app_key(conf, prefix)
203
+ if conf.key?("#{prefix}_key_path")
204
+ fname = File.expand_path(conf["#{prefix}_key_path"], __FILE__)
205
+ Auth.key_from_file(fname, Auth.app_algorithm)
206
+ elsif conf.key?("#{prefix}_key_env_variable")
207
+ varname = conf["#{prefix}_key_env_variable"]
208
+ Auth.key_from_env(varname, Auth.app_algorithm)
209
+ elsif conf.key?("#{prefix}_key")
210
+ field = "#{prefix}_key"
211
+ Auth.key_from_settings(field, Auth.app_algorithm)
212
+ elsif conf.key?("#{prefix}_enabled")
213
+ fname = File.expand_path(Auth::DEFAULT_VERIFY_KEY_PATH, __FILE__)
214
+ Auth.key_from_file(fname, Auth.app_algorithm)
215
+ else
216
+ nil
217
+ end
218
+ end
219
+
220
+ @@app_signing_key = Auth.init_app_key(@@conf, 'signing')
221
+
222
+ @@app_verify_key = Auth.init_app_key(@@conf, 'verify')
205
223
 
206
224
  def self.settings_reloaded
207
225
  @@conf = ExoBasic::Settings.loaded['user_auth']
208
226
 
209
- @@app_signing_key = ExoBasic::Settings.try_get_key(@@conf,
210
- true,
211
- 'signing_enabled') ?
212
- Auth.key_from_file(
213
- File.expand_path(
214
- ExoBasic::Settings.try_get_key(@@conf,
215
- Auth::DEFAULT_SIGNING_KEY_PATH,
216
- 'signing_key_path'),
217
- __FILE__),
218
- Auth.app_algorithm) :
219
- nil
220
-
221
- @@app_verify_key = ExoBasic::Settings.try_get_key(@@conf,
222
- true,
223
- 'verify_enabled') ?
224
- Auth.key_from_file(
225
- File.expand_path(
226
- ExoBasic::Settings.try_get_key(@@conf,
227
- Auth::DEFAULT_VERIFY_KEY_PATH,
228
- 'verify_key_path'),
229
- __FILE__),
230
- Auth.app_algorithm) :
231
- nil
227
+ @@app_signing_key = Auth.init_app_key(@@conf, 'signing')
228
+
229
+ @@app_verify_key = Auth.init_app_key(@@conf, 'verify')
232
230
  end
233
231
 
234
232
  def self.get_app_signing_key
@@ -1,3 +1,3 @@
1
1
  module ExoAuth
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exoauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dionysios Kakolyris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-18 00:00:00.000000000 Z
11
+ date: 2022-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.0
19
+ version: 2.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.0
26
+ version: 2.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: exobasic
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.0
33
+ version: 0.1.2
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
- version: 0.1.0
40
+ version: 0.1.2
41
41
  description: Exotic Auth Helpers
42
42
  email:
43
43
  - contact@exotic.industries