exoauth 0.1.0 → 0.1.1

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: 456dcc39fe3e7ec3fc82d5a1ffaeaf2e96b27c508cd31d7684b8d3c6483a262d
4
+ data.tar.gz: ede542d5edd11be158c01fba4f1a364f62cb9a47dfb19dfb79c68c719fa33f0b
5
5
  SHA512:
6
- metadata.gz: 3c89974b8622adbab518a1b5a76c8a87f17a25b8da419347234433d1884cc866aa57f26ee1988913a29a5055c992b8cb06f07b1c390b83322b76652b047932e1
7
- data.tar.gz: 2e8a34be42eb834f0ba76b42b9e5c5a19ffe41549576bdafac5a87366764263cbd7f989e0f90d9950410ba50f24f80dc9da81fcd52821c21dff87b892a5c0977
6
+ metadata.gz: 5c68fc8d512b173d8e6413202d1a75d67ba210dd83795768714b0037ad1a4e3575b0d341e07d6f3df4d1421948cc279c8594515938e78b0acf1d7ed3dd4cb9a8
7
+ data.tar.gz: 872a4d6381b68f4bd9e2b17f9a9f2c2f2716f575ae92931d53b2970f088b1b905b93ef8a5756917405187cc7ca17ebb2cf9ee144e5411c055769bd4220df25ca
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.1"
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.1
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-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt