nomis-api-client 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 +4 -4
- data/lib/nomis/api.rb +1 -0
- data/lib/nomis/api/auth_token.rb +33 -17
- data/lib/nomis/api/get.rb +0 -1
- data/lib/nomis/api/token_mismatch_error.rb +6 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61abe8cac6c008008682e6496d4ec8b6678d3d54
|
4
|
+
data.tar.gz: 7b3f94e1036fc8be3cddb483529109de5e145e90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2a5063b7ad15686499cd2483c4eafb86c518f27b13613b48d535d599023c6343687277fb756736af94dbaba76e82d2b621d29adf73ad595a610ff94552926b8
|
7
|
+
data.tar.gz: a04e789fb87a8f53e9ee8919d0a0d3281bf51698ff9e5c97145430e78492f76df6396a1bd6b83b1c4f4a76e89f170f0dc6de0222b04a1301b6df95ae3a698d78
|
data/lib/nomis/api.rb
CHANGED
data/lib/nomis/api/auth_token.rb
CHANGED
@@ -6,7 +6,7 @@ module NOMIS
|
|
6
6
|
module API
|
7
7
|
# Encapsulates the complexity of generating a JWT bearer token
|
8
8
|
class AuthToken
|
9
|
-
attr_accessor :client_token, :client_key, :iat_fudge_factor
|
9
|
+
attr_accessor :client_token, :client_key, :iat_fudge_factor, :now
|
10
10
|
|
11
11
|
# iat_fudge_factor allows you to correct for time drift between your
|
12
12
|
# client and the target server.
|
@@ -29,14 +29,12 @@ module NOMIS
|
|
29
29
|
def bearer_token
|
30
30
|
validate_keys!
|
31
31
|
|
32
|
-
auth_token = JWT.encode(payload, client_key, 'ES256')
|
33
|
-
|
34
32
|
"Bearer #{auth_token}"
|
35
33
|
end
|
36
34
|
|
37
35
|
def payload
|
38
36
|
{
|
39
|
-
iat:
|
37
|
+
iat: current_timestamp + iat_fudge_factor,
|
40
38
|
token: client_token
|
41
39
|
}
|
42
40
|
end
|
@@ -47,26 +45,44 @@ module NOMIS
|
|
47
45
|
# error message can only say that the generated JWT token does not
|
48
46
|
# validate.
|
49
47
|
def validate_keys!
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
unless client_pub_base64 == expected_client_pub
|
57
|
-
raise 'Incorrect private key supplied ' \
|
58
|
-
+ '(does not match public key within token)'
|
48
|
+
unless client_public_key_base64 == expected_client_public_key
|
49
|
+
raise TokenMismatchError,
|
50
|
+
'Incorrect private key supplied ' \
|
51
|
+
+ '(does not match public key within token)',
|
52
|
+
caller
|
59
53
|
end
|
60
54
|
end
|
61
55
|
|
62
56
|
protected
|
63
57
|
|
64
|
-
def
|
65
|
-
|
58
|
+
def auth_token
|
59
|
+
JWT.encode(payload, client_key, 'ES256')
|
60
|
+
end
|
61
|
+
|
62
|
+
def client_public_key_base64
|
63
|
+
client_public_key = OpenSSL::PKey::EC.new client_key
|
64
|
+
client_public_key.private_key = nil
|
65
|
+
Base64.strict_encode64(client_public_key.to_der)
|
66
|
+
end
|
67
|
+
|
68
|
+
def expected_client_public_key
|
69
|
+
JWT.decode(client_token, nil, nil)[0]['key']
|
70
|
+
end
|
71
|
+
|
72
|
+
def current_timestamp
|
73
|
+
now || Time.now.to_i
|
74
|
+
end
|
75
|
+
|
76
|
+
def default_client_key(params = {})
|
77
|
+
read_client_key_file(
|
78
|
+
params[:client_key_file] || ENV['NOMIS_API_CLIENT_KEY_FILE']
|
79
|
+
)
|
66
80
|
end
|
67
81
|
|
68
|
-
def default_client_token(params={})
|
69
|
-
read_client_key_file(
|
82
|
+
def default_client_token(params = {})
|
83
|
+
read_client_key_file(
|
84
|
+
params[:client_token_file] || ENV['NOMIS_API_CLIENT_TOKEN_FILE']
|
85
|
+
)
|
70
86
|
end
|
71
87
|
|
72
88
|
def default_iat_fudge_factor(params={})
|
data/lib/nomis/api/get.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nomis-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Al Davidson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/nomis/api/get.rb
|
54
54
|
- lib/nomis/api/parsed_response.rb
|
55
55
|
- lib/nomis/api/post.rb
|
56
|
+
- lib/nomis/api/token_mismatch_error.rb
|
56
57
|
- lib/nomis_api_client_ruby.rb
|
57
58
|
homepage: http://rubygems.org/gems/nomis_api_client_ruby
|
58
59
|
licenses:
|