wso2_toolbox 0.2.3 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0df74c3b934dca8ce0a6115f19953de2be5ba2c
4
- data.tar.gz: e7ef632221da9343dedcbf8883e8d69afcc0205d
3
+ metadata.gz: 7f8a8eff153546833fe2467480aad2bf4e3be98b
4
+ data.tar.gz: f4850b59de521a4245bc11674a95967bda0d5a9f
5
5
  SHA512:
6
- metadata.gz: b30d842325c67739c594a13dfa2c8dee5af29716c84bf72374b6360658271cc0974b77dca4b6b51b1c2cb2b72515601f42ebcaf16e4daacf57b5632a4788dd87
7
- data.tar.gz: 78720b4a1c8c2a5d07a1bf02e21d3d15f9f6f522f0a3d51618dca01f1dafe3a35c12e5563deecfef516eed29a390d2cffdfe7203e78357eb1a667d8b045f6ea8
6
+ metadata.gz: ad943f3a94528589c06902bf4db315bfe17f69efff60e2a8c21ebe22b2531c9b954590b680c8021c9ca77bba4b2126130872694916eb3541c8f29f24fcaa5726
7
+ data.tar.gz: 15ac3d2a80c82ba018d04bb9aaa586b47836d5b4774c8c3aae19d584bef07124206a42e61dd8a790c1ce658c2bd05775c5aa114b65e597d040b8f3c94bb8e5dc
data/.env.development CHANGED
@@ -2,3 +2,5 @@
2
2
  TOKEN_USERNAME='svc-cedrobco_h'
3
3
  TOKEN_PASSWORD='Toor@2017'
4
4
  TOKEN_URL='http://172.16.13.67:8010/auth/users/login'
5
+ TOKEN_REFRESH_URL='http://172.16.13.67:8010/auth/refresh_token'
6
+ TOKEN_REVOKE_URL='http://172.16.13.67:8010/auth/revoke_token'
data/.env.pipelines CHANGED
@@ -1,2 +1,6 @@
1
1
  # generate token URL
2
+ TOKEN_USERNAME='svc-cedrobco_h'
3
+ TOKEN_PASSWORD='Toor@2017'
2
4
  TOKEN_URL='http://172.16.13.67:8010/auth/users/login'
5
+ TOKEN_REFRESH_URL='http://172.16.13.67:8010/auth/refresh_token'
6
+ TOKEN_REVOKE_URL='http://172.16.13.67:8010/auth/revoke_token'
data/CHANGELOG.md CHANGED
@@ -13,3 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
13
13
  ## [0.2.2] - 2018-01-15
14
14
  ### Changed
15
15
  - Fix time parser
16
+
17
+ ## [0.3.0] - 2018-05-11
18
+ ### Changed
19
+ - Refresh auth token when invalid
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
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Wso2Toolbox
4
4
  class Configuration
5
- attr_accessor :token_username, :token_password, :token_url
5
+ attr_accessor :token_username, :token_password, :token_url,
6
+ :refresh_token_url, :revoke_token_url
6
7
  end
7
8
  end
@@ -10,7 +10,8 @@ module Wso2Toolbox
10
10
  TOKEN_DELAY = 5.minutes
11
11
 
12
12
  def generate_token
13
- new_token unless active_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
- Setting.token_for_job =
23
- "#{token_params[:token_type]} #{token_params[:access_token]}"
24
- Setting.token_time_for_job =
25
- Time.now + token_params[:expires_in].to_i.seconds
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(config.token_url, params.to_json,
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wso2Toolbox
4
- VERSION = '0.2.3'
4
+ VERSION = '0.3.0'
5
5
  end
data/wso2_toolbox.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'wso2_toolbox/version'
6
6
 
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.2.3
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-02-19 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack