dina 0.4.3.0 → 0.4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dina/authentication/authentication.rb +41 -24
- data/lib/dina/exceptions.rb +2 -0
- data/lib/dina/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a77888d0a10acb3970bf9591e736bc8659d4bd4df79d7da5635b59db1e6c26d
|
4
|
+
data.tar.gz: 1ba52d47cff3f85e4d0bed7ec62b388fc51f2e8a00f35dd7e578f310f0452a75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff956f4b1fe2d20d22a2f98e9139e0812e54f1c05433a8a5bd8372880258662fdc27d81ccd75d55d5037f3f12a9490e1e1b7bc93faf33d4cd2a8bc47ca3b212
|
7
|
+
data.tar.gz: 8cc16fd12372ad0e50fd5b90b0ac25c83fb9b389e76f06e60cf4f613a3a5b44e0262e5ec0a379518d0be332d005e314de7457c600d033a4b8730745ac56ff996
|
@@ -18,16 +18,27 @@ module Dina
|
|
18
18
|
#
|
19
19
|
# @param options [Hash] the configuration options
|
20
20
|
def self.config(options = {})
|
21
|
+
raise ConfigItemMissing, "Missing token_store_file from config." unless options[:token_store_file]
|
22
|
+
raise ConfigItemMissing, "Missing user from config." unless options[:user]
|
23
|
+
raise ConfigItemMissing, "Missing password from config." unless options[:password]
|
24
|
+
raise ConfigItemMissing, "Missing server_name from config." unless options[:server_name]
|
25
|
+
raise ConfigItemMissing, "Missing client_id from config." unless options[:client_id]
|
26
|
+
raise ConfigItemMissing, "Missing endpoint_url from config." unless options[:endpoint_url]
|
27
|
+
raise ConfigItemMissing, "Missing authorization_url from config." unless options[:authorization_url]
|
28
|
+
raise ConfigItemMissing, "Missing realm from config." unless options[:realm]
|
29
|
+
|
30
|
+
if !options[:token_store_file].instance_of?(String) || !::File.exist?(options[:token_store_file])
|
31
|
+
raise TokenStoreFileNotFound
|
32
|
+
end
|
33
|
+
|
21
34
|
@token_store_file = options[:token_store_file]
|
22
35
|
@user = options[:user]
|
23
36
|
@password = options[:password]
|
24
37
|
@server_name = options[:server_name]
|
25
38
|
@client_id = options[:client_id]
|
26
39
|
@endpoint_url = options[:endpoint_url]
|
27
|
-
|
28
|
-
|
29
|
-
Keycloak.auth_server_url = @authorization_url
|
30
|
-
Keycloak.realm = @realm
|
40
|
+
Keycloak.auth_server_url = options[:authorization_url]
|
41
|
+
Keycloak.realm = options[:realm]
|
31
42
|
end
|
32
43
|
|
33
44
|
# Gets, sets, and renews a Bearer access token as required
|
@@ -47,10 +58,34 @@ module Dina
|
|
47
58
|
end
|
48
59
|
|
49
60
|
class << self
|
50
|
-
attr_accessor :
|
61
|
+
attr_accessor :endpoint_url
|
51
62
|
|
52
63
|
private
|
53
64
|
|
65
|
+
def access_token
|
66
|
+
begin
|
67
|
+
read_token[@server_name.to_sym][:access_token]
|
68
|
+
rescue
|
69
|
+
raise TokenStoreContentInvalid
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def refresh_token
|
74
|
+
begin
|
75
|
+
read_token[@server_name.to_sym][:refresh_token]
|
76
|
+
rescue
|
77
|
+
raise TokenStoreContentInvalid
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def auth_expiry
|
82
|
+
begin
|
83
|
+
read_token[@server_name.to_sym][:auth_expiry]
|
84
|
+
rescue
|
85
|
+
raise TokenStoreContentInvalid
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
54
89
|
def get_token
|
55
90
|
response = Keycloak::Client.get_token(
|
56
91
|
@user,
|
@@ -80,29 +115,11 @@ module Dina
|
|
80
115
|
end
|
81
116
|
end
|
82
117
|
|
83
|
-
def access_token
|
84
|
-
read_token[:access_token]
|
85
|
-
end
|
86
|
-
|
87
|
-
def refresh_token
|
88
|
-
read_token[:refresh_token]
|
89
|
-
end
|
90
|
-
|
91
|
-
def auth_expiry
|
92
|
-
read_token[:auth_expiry] rescue "9999-01-01 00:00:00 -0500"
|
93
|
-
end
|
94
|
-
|
95
118
|
def read_token
|
96
|
-
|
97
|
-
JSON.parse(::File.read(@token_store_file), symbolize_names: true)[@server_name.to_sym] rescue default_token
|
98
|
-
end
|
99
|
-
|
100
|
-
def default_token
|
101
|
-
{ access_token: nil, refresh_token: nil, auth_expiry: "9999-01-01 00:00:00 -0500" }
|
119
|
+
JSON.parse(::File.read(@token_store_file), symbolize_names: true)
|
102
120
|
end
|
103
121
|
|
104
122
|
def save_token(access_token:, refresh_token:, auth_expiry:)
|
105
|
-
raise TokenStoreFileNotFound unless @token_store_file.instance_of?(String) && ::File.exist?(@token_store_file)
|
106
123
|
data_hash = JSON.parse(::File.read(@token_store_file), symbolize_names: true) rescue {}
|
107
124
|
data_hash[@server_name.to_sym] = {
|
108
125
|
access_token: access_token,
|
data/lib/dina/exceptions.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Dina
|
2
2
|
class DinaException < StandardError; end
|
3
3
|
class TokenStoreFileNotFound < DinaException; end
|
4
|
+
class TokenStoreContentInvalid < DinaException; end
|
5
|
+
class ConfigItemMissing < DinaException; end
|
4
6
|
class ObjectInvalid < DinaException; end
|
5
7
|
class PropertyValueInvalid < ObjectInvalid; end
|
6
8
|
end
|
data/lib/dina/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dina
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David P. Shorthouse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|