wso2_toolbox 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.development +2 -0
- data/.env.pipelines +4 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/lib/wso2_toolbox/configuration.rb +2 -1
- data/lib/wso2_toolbox/token_manager/adapters/rails_cached_adapter.rb +35 -6
- data/lib/wso2_toolbox/token_manager/api_manager_service.rb +11 -3
- data/lib/wso2_toolbox/version.rb +1 -1
- data/wso2_toolbox.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f8a8eff153546833fe2467480aad2bf4e3be98b
|
4
|
+
data.tar.gz: f4850b59de521a4245bc11674a95967bda0d5a9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad943f3a94528589c06902bf4db315bfe17f69efff60e2a8c21ebe22b2531c9b954590b680c8021c9ca77bba4b2126130872694916eb3541c8f29f24fcaa5726
|
7
|
+
data.tar.gz: 15ac3d2a80c82ba018d04bb9aaa586b47836d5b4774c8c3aae19d584bef07124206a42e61dd8a790c1ce658c2bd05775c5aa114b65e597d040b8f3c94bb8e5dc
|
data/.env.development
CHANGED
data/.env.pipelines
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -27,6 +27,8 @@ fill in the attributes:
|
|
27
27
|
```
|
28
28
|
Wso2Toolbox.configure do |config|
|
29
29
|
config.token_url = ENV['GENERATE_TOKEN_DEV_URL']
|
30
|
+
config.refresh_token_url = ENV['REFRESH_TOKEN_DEV_URL']
|
31
|
+
config.revoke_token_url = ENV['REVOKE_TOKEN_DEV_URL']
|
30
32
|
config.token_username = ENV['GENERATE_TOKEN_DEV_USERNAME']
|
31
33
|
config.token_password = ENV['GENERATE_TOKEN_DEV_PASSWORD']
|
32
34
|
end
|
@@ -10,7 +10,8 @@ module Wso2Toolbox
|
|
10
10
|
TOKEN_DELAY = 5.minutes
|
11
11
|
|
12
12
|
def generate_token
|
13
|
-
new_token
|
13
|
+
new_token if expired_token?
|
14
|
+
refresh_token unless active_token?
|
14
15
|
store_token(Setting.token_for_job)
|
15
16
|
end
|
16
17
|
|
@@ -19,18 +20,46 @@ module Wso2Toolbox
|
|
19
20
|
def new_token
|
20
21
|
token_params =
|
21
22
|
Wso2Toolbox::TokenManager::ApiManagerService.create_token
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
build_settings(token_params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def refresh_token
|
27
|
+
token_params =
|
28
|
+
Wso2Toolbox::TokenManager::ApiManagerService.refresh_token(
|
29
|
+
Setting.refresh_token
|
30
|
+
)
|
31
|
+
Wso2Toolbox::TokenManager::ApiManagerService.revoke_token(
|
32
|
+
Setting.access_token
|
33
|
+
)
|
34
|
+
build_settings(token_params)
|
26
35
|
end
|
27
36
|
|
28
37
|
def store_token(token)
|
29
38
|
RequestStore.store[:token] = token
|
30
39
|
end
|
31
40
|
|
41
|
+
def build_settings(token_params)
|
42
|
+
Setting.access_token = token_params[:access_token]
|
43
|
+
Setting.refresh_token = token_params[:refresh_token]
|
44
|
+
build_token_for_job(token_params[:token_type],
|
45
|
+
token_params[:access_token])
|
46
|
+
build_token_time_for_job(token_params[:expires_in])
|
47
|
+
end
|
48
|
+
|
49
|
+
def build_token_for_job(token_type, access_token)
|
50
|
+
Setting.token_for_job = "#{token_type} #{access_token}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_token_time_for_job(expires_in)
|
54
|
+
Setting.token_time_for_job = expires_in.to_i.seconds.from_now
|
55
|
+
end
|
56
|
+
|
57
|
+
def expired_token?
|
58
|
+
return true unless Setting.token_time_for_job
|
59
|
+
Time.now > Time.parse(Setting.token_time_for_job)
|
60
|
+
end
|
61
|
+
|
32
62
|
def active_token?
|
33
|
-
return false unless Setting.token_time_for_job
|
34
63
|
Time.parse(Setting.token_time_for_job.to_s) - TOKEN_DELAY > Time.now
|
35
64
|
end
|
36
65
|
end
|
@@ -8,7 +8,15 @@ module Wso2Toolbox
|
|
8
8
|
module ApiManagerService
|
9
9
|
class << self
|
10
10
|
def create_token
|
11
|
-
post(build_params)
|
11
|
+
post(config.token_url, build_params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def refresh_token(token)
|
15
|
+
post(config.refresh_token_url, token: token)
|
16
|
+
end
|
17
|
+
|
18
|
+
def revoke_token(token)
|
19
|
+
post(config.revoke_token_url, token: token)
|
12
20
|
end
|
13
21
|
|
14
22
|
private_class_method
|
@@ -24,8 +32,8 @@ module Wso2Toolbox
|
|
24
32
|
}
|
25
33
|
end
|
26
34
|
|
27
|
-
def post(params)
|
28
|
-
response = RestClient.post(
|
35
|
+
def post(url, params)
|
36
|
+
response = RestClient.post(url, params.to_json,
|
29
37
|
content_type: :json)
|
30
38
|
JSON.parse(response).with_indifferent_access
|
31
39
|
end
|
data/lib/wso2_toolbox/version.rb
CHANGED
data/wso2_toolbox.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wso2_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abner Carleto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|