soar_authentication_token 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/keypair-generator +13 -0
- data/lib/soar_authentication_token/token_generator.rb +5 -4
- data/lib/soar_authentication_token/token_validator.rb +5 -5
- data/lib/soar_authentication_token/version.rb +1 -1
- data/spec/token_generator_spec.rb +4 -4
- data/spec/token_validator_spec.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e3c701d097f5b136e50e3f178c444e6b604f2da
|
4
|
+
data.tar.gz: 0178b46dd7f0e2a2a7d15e9cb73b422b00165d30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ede08945abe0fe5da8cdb4ce59f8fb7853bc52fdc3c9f160e0722b65a0fb2ac2b1c01efd3e8e20671df1d3ca8eab03ceac98f1777b5d72a2f2c0d49c161e970e
|
7
|
+
data.tar.gz: 0108db7ca629b57f7c5398764c98cdb208557aab62cdfec6e96d82d4b3bba7e7529ee5e3cbf240898191c5203130e3f67e2360051a4662cfa5247a95d1c2592c
|
data/bin/keypair-generator
CHANGED
@@ -5,6 +5,7 @@ $:.unshift File.expand_path("../../lib", bin_file)
|
|
5
5
|
|
6
6
|
require 'soar_authentication_token'
|
7
7
|
require 'yaml'
|
8
|
+
require 'json'
|
8
9
|
|
9
10
|
class Main
|
10
11
|
|
@@ -16,7 +17,19 @@ class Main
|
|
16
17
|
'private_key' => private_key,
|
17
18
|
'public_key' => public_key
|
18
19
|
}
|
20
|
+
puts "------------"
|
21
|
+
puts "YAML Format:"
|
22
|
+
puts "------------"
|
19
23
|
print configuration.to_yaml
|
24
|
+
puts ""
|
25
|
+
puts "------------"
|
26
|
+
puts "JSON Format:"
|
27
|
+
puts "------------"
|
28
|
+
print configuration.to_json
|
29
|
+
puts ""
|
30
|
+
puts ""
|
31
|
+
puts "------------"
|
32
|
+
|
20
33
|
end
|
21
34
|
end
|
22
35
|
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'soar_xt'
|
2
2
|
require 'jwt'
|
3
|
+
require 'securerandom'
|
3
4
|
|
4
5
|
module SoarAuthenticationToken
|
5
6
|
class TokenGenerator
|
6
7
|
DEFAULT_CONFIGURATION = {
|
7
|
-
|
8
|
-
|
9
|
-
:url => ''
|
8
|
+
'mode' => 'remote',
|
9
|
+
'url' => ''
|
10
10
|
} unless defined? DEFAULT_CONFIGURATION; DEFAULT_CONFIGURATION.freeze
|
11
11
|
|
12
12
|
def initialize(configuration)
|
13
13
|
@configuration = merge_with_default_configuration(configuration)
|
14
14
|
validate_configuration
|
15
|
-
@private_key = OpenSSL::PKey::EC.new(@configuration[
|
15
|
+
@private_key = OpenSSL::PKey::EC.new(@configuration['private_key'])
|
16
16
|
end
|
17
17
|
|
18
18
|
def generate(authenticated_identifier:)
|
@@ -36,6 +36,7 @@ module SoarAuthenticationToken
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def merge_with_default_configuration(configuration)
|
39
|
+
configuration = {} unless configuration
|
39
40
|
Hash.deep_merge(DEFAULT_CONFIGURATION,configuration)
|
40
41
|
end
|
41
42
|
end
|
@@ -4,20 +4,20 @@ require 'jwt'
|
|
4
4
|
module SoarAuthenticationToken
|
5
5
|
class TokenValidator
|
6
6
|
DEFAULT_CONFIGURATION = {
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
'mode' => 'local',
|
8
|
+
'public_key' => '',
|
9
|
+
'url' => ''
|
10
10
|
} unless defined? DEFAULT_CONFIGURATION; DEFAULT_CONFIGURATION.freeze
|
11
11
|
|
12
12
|
def initialize(configuration)
|
13
13
|
@configuration = merge_with_default_configuration(configuration)
|
14
14
|
validate_configuration
|
15
|
-
@public_key = OpenSSL::PKey::EC.new(@configuration[
|
15
|
+
@public_key = OpenSSL::PKey::EC.new(@configuration['public_key'])
|
16
16
|
@public_key.private_key = nil
|
17
17
|
end
|
18
18
|
|
19
19
|
def validate(authentication_token)
|
20
|
-
return validate_locally(authentication_token) if 'local' == @configuration[
|
20
|
+
return validate_locally(authentication_token) if 'local' == @configuration['mode']
|
21
21
|
return validate_remotely(authentication_token)
|
22
22
|
end
|
23
23
|
|
@@ -8,12 +8,12 @@ describe SoarAuthenticationToken::TokenGenerator do
|
|
8
8
|
|
9
9
|
before :each do
|
10
10
|
generator_configuration = {
|
11
|
-
|
12
|
-
|
11
|
+
'mode' => 'local',
|
12
|
+
'private_key' => @private_key
|
13
13
|
}
|
14
14
|
validator_configuration = {
|
15
|
-
|
16
|
-
|
15
|
+
'mode' => 'local',
|
16
|
+
'public_key' => @public_key
|
17
17
|
}
|
18
18
|
@iut = SoarAuthenticationToken::TokenGenerator.new(generator_configuration)
|
19
19
|
@validator = SoarAuthenticationToken::TokenValidator.new(validator_configuration)
|
@@ -8,16 +8,16 @@ describe SoarAuthenticationToken::TokenValidator do
|
|
8
8
|
@invalid_private_key, @invalid_public_key = keypair_generator.generate
|
9
9
|
@test_identifier = 'a@b.co.za'
|
10
10
|
@valid_generator_configuration = {
|
11
|
-
|
12
|
-
|
11
|
+
'mode' => 'local',
|
12
|
+
'private_key' => @valid_private_key
|
13
13
|
}
|
14
14
|
@invalid_generator_configuration = {
|
15
|
-
|
16
|
-
|
15
|
+
'mode' => 'local',
|
16
|
+
'private_key' => @invalid_private_key
|
17
17
|
}
|
18
18
|
@validator_configuration = {
|
19
|
-
|
20
|
-
|
19
|
+
'mode' => 'local',
|
20
|
+
'public_key' => @valid_public_key
|
21
21
|
}
|
22
22
|
@valid_generator = SoarAuthenticationToken::TokenGenerator.new(@valid_generator_configuration)
|
23
23
|
@invalid_generator = SoarAuthenticationToken::TokenGenerator.new(@invalid_generator_configuration)
|