dina 0.4.3.0 → 0.5.0.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 +43 -26
- data/lib/dina/exceptions.rb +2 -0
- data/lib/dina/models/base_model.rb +1 -1
- data/lib/dina/version.rb +2 -2
- 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: cee08dca65cf1c04b4c2b03aa08e9686a4684ea96b484fe6a4b1a9e32d8001a8
|
4
|
+
data.tar.gz: c247128c86df604291f3ec985254e59bc676b120481e8a8736c1033d3adfb063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78ea88a086216ae6a5d27c6121cc6d345537a17902a9cd2c0dd4caaf4748a9c45d3c5243ea8d06d4ffa7d09c57a7da0092677bc20e3187d16f7517782ef3af2e
|
7
|
+
data.tar.gz: da1011c76dcd1fb72f1cd26623cb0cf02835535b091bb19e3bcd76cc393343e238b3ffde0419ff98c53f90a5278d0d0908ccff481f9e10ffe6f6a46c11cca580
|
@@ -11,23 +11,34 @@ module Dina
|
|
11
11
|
# password: "password provided by DINA admin in Keycloak",
|
12
12
|
# server_name: "used locally to reference the token",
|
13
13
|
# client_id: "provided by DINA admin in Keycloak",
|
14
|
-
# endpoint_url: "DINA API URL",
|
15
|
-
# authorization_url: "Keycloak authorization URL".
|
14
|
+
# endpoint_url: "DINA API URL without terminating slash",
|
15
|
+
# authorization_url: "Keycloak authorization URL without terminating slash".
|
16
16
|
# realm: "provided by DINA admin in Keycloak"
|
17
17
|
# }
|
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
|
+
version: 0.5.0.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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|