bsm-sso-client 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f0c1a3a68deb279c8c0ab07902467feb474f63b4
4
- data.tar.gz: d65454a036a2b8a8eb490c46a1f4f5e82eafffba
2
+ SHA256:
3
+ metadata.gz: e2130651c34cb85c562ab688d121eed6f6d709c002ca6388d9a6742b19f2e134
4
+ data.tar.gz: 6fd1a90fb066f52d007086f30e5d2590639f3df17c4994b50bb1dbd89d6e7a3f
5
5
  SHA512:
6
- metadata.gz: 51490c8cb4da30a9e36e1c4591b86bdf8f44d3018081e6b471b478a9184aa139514973b9863af58df2ed15e4dde0bb1a8d66a710258908a850e9815af680cfc4
7
- data.tar.gz: 06e1b7fae948976796355ba5b17de669969d849c36f0926a28950855cf89a58af16c167f7233480470ea7bb8a68b8eb7eb1f07516aaa74b20ac30040062d463f
6
+ metadata.gz: 37811dc50112157d7ca226004bebd51f9ebdd77e7986d173bdaa7509ce88a7447bf17fa01f9a401bae8d0a04563e399a2eaabf34c2fe3512f0fff81a8da9d698
7
+ data.tar.gz: 3e84ae2f5bbbc07f2c7f990f957abd2944e7b123d779f7f6c38701f4a2b50ea07e63c81dc10ce49a21a9e76e8642783b1964ceb33f50391342918fca8a831d48
@@ -69,7 +69,7 @@ module Bsm
69
69
  #
70
70
  # # config/initializers/sso.rb
71
71
  # Bsm::Sso::Client.configure do |c|
72
- # c.site = "https://sso.example.com"
72
+ # c.site = "https://sso.test.host"
73
73
  # c.secret = "m4GHRWxvXiL3ZSR8adShpqNWXmepkqeyUqRfpB8F"
74
74
  # end
75
75
  def configure(&block)
@@ -1,89 +1,90 @@
1
- require 'excon'
2
- require 'active_support/json'
3
- require 'active_support/core_ext/object/to_query'
4
- require 'active_support/core_ext/hash/keys'
5
-
6
- class Bsm::Sso::Client::AbstractResource < Hash
7
-
8
- class << self
9
-
10
- # @param [String] url
11
- def site=(url)
12
- @site = Excon.new url,
13
- :idempotent => true,
14
- :expects => [200, 422],
15
- :headers => { 'Accept' => Mime[:json].to_s, 'Content-Type' => Mime[:json].to_s }
16
- end
17
-
18
- # @return [Excon::Connection] site connection
19
- def site
20
- @site || (superclass.respond_to?(:site) && superclass.site) || raise("No site specified for #{name}. Please specify #{name}.site = 'http://your.sso.host'")
21
- end
22
-
23
- # @return [Hash] default headers
24
- def headers
25
- { 'Authorization' => Bsm::Sso::Client.verifier.generate(Bsm::Sso::Client.token_timeout.from_now) }
26
- end
27
-
28
- # @param [String] path
29
- # @param [Hash] params, request params - see Excon::Connection#request
30
- # @return [Bsm::Sso::Client::AbstractResource] fetches object from remote
31
- def get(path, params = {})
32
- params[:query] ||= params.delete(:params)
33
- collection = params.delete(:collection)
34
- params = params.merge(:path => path)
35
- params[:headers] = (params[:headers] || {}).merge(headers)
36
-
37
- response = site.get(params)
38
- return (collection ? [] : nil) unless response.status == 200
39
-
40
- result = ActiveSupport::JSON.decode(response.body)
41
- result = Array.wrap(result).map do |record|
42
- instance = new(record)
43
- instance if instance.id
44
- end.compact
45
- collection ? result : result.first
46
- rescue MultiJson::DecodeError
47
- collection ? [] : nil
48
- end
49
-
50
- end
51
-
52
- # Constuctor
53
- # @param [Hash,NilClass] attributes the attributes to assign
54
- def initialize(attributes = nil)
55
- super()
56
- update(attributes.stringify_keys) if attributes.is_a?(Hash)
57
- end
58
-
59
- # @return [Integer] ID, the primary key
60
- def id
61
- self["id"]
62
- end
63
-
64
- # @return [Boolean] true, if method exists?
65
- def respond_to?(method, *)
66
- super || key?(method.to_s.sub(/[=?]$/, ''))
67
- end
68
-
69
- # @return [Hash] attributes hash
70
- def attributes
71
- dup
72
- end
73
-
74
- protected
75
-
76
- def method_missing(method, *arguments)
77
- method, punctation = method.to_s.sub(/([=?])$/, ''), $1
78
-
79
- case punctation
80
- when "="
81
- store(method, arguments.first)
82
- when "?"
83
- self[method]
84
- else
85
- key?(method) ? fetch(method) : super
86
- end
87
- end
88
-
89
- end
1
+ require 'excon'
2
+ require 'active_support/json'
3
+ require 'active_support/core_ext/object/to_query'
4
+ require 'active_support/core_ext/hash/keys'
5
+
6
+ class Bsm::Sso::Client::AbstractResource < Hash
7
+
8
+ class << self
9
+
10
+ # @param [String] url
11
+ def site=(url)
12
+ @site = Excon.new url,
13
+ mock: defined?(WebMock),
14
+ idempotent: true,
15
+ expects: [200, 422],
16
+ headers: { 'Accept' => Mime[:json].to_s, 'Content-Type' => Mime[:json].to_s }
17
+ end
18
+
19
+ # @return [Excon::Connection] site connection
20
+ def site
21
+ @site || (superclass.respond_to?(:site) && superclass.site) || raise("No site specified for #{name}. Please specify #{name}.site = 'http://your.sso.host'")
22
+ end
23
+
24
+ # @return [Hash] default headers
25
+ def headers
26
+ { 'Authorization' => Bsm::Sso::Client.verifier.generate(Bsm::Sso::Client.token_timeout.from_now) }
27
+ end
28
+
29
+ # @param [String] path
30
+ # @param [Hash] params, request params - see Excon::Connection#request
31
+ # @return [Bsm::Sso::Client::AbstractResource] fetches object from remote
32
+ def get(path, params = {})
33
+ params[:query] ||= params.delete(:params)
34
+ collection = params.delete(:collection)
35
+ params = params.merge(:path => path)
36
+ params[:headers] = (params[:headers] || {}).merge(headers)
37
+
38
+ response = site.get(params)
39
+ return (collection ? [] : nil) unless response.status == 200
40
+
41
+ result = ActiveSupport::JSON.decode(response.body)
42
+ result = Array.wrap(result).map do |record|
43
+ instance = new(record)
44
+ instance if instance.id
45
+ end.compact
46
+ collection ? result : result.first
47
+ rescue ActiveSupport::JSON.parse_error
48
+ collection ? [] : nil
49
+ end
50
+
51
+ end
52
+
53
+ # Constuctor
54
+ # @param [Hash,NilClass] attributes the attributes to assign
55
+ def initialize(attributes = nil)
56
+ super()
57
+ update(attributes.stringify_keys) if attributes.is_a?(Hash)
58
+ end
59
+
60
+ # @return [Integer] ID, the primary key
61
+ def id
62
+ self["id"]
63
+ end
64
+
65
+ # @return [Boolean] true, if method exists?
66
+ def respond_to?(method, *)
67
+ super || key?(method.to_s.sub(/[=?]$/, ''))
68
+ end
69
+
70
+ # @return [Hash] attributes hash
71
+ def attributes
72
+ dup
73
+ end
74
+
75
+ protected
76
+
77
+ def method_missing(method, *arguments)
78
+ method, punctation = method.to_s.sub(/([=?])$/, ''), $1
79
+
80
+ case punctation
81
+ when "="
82
+ store(method, arguments.first)
83
+ when "?"
84
+ self[method]
85
+ else
86
+ key?(method) ? fetch(method) : super
87
+ end
88
+ end
89
+
90
+ end
@@ -1,3 +1,3 @@
1
- module Bsm::Sso::Client::Cached
2
- autoload :ActiveRecord, "bsm/sso/client/cached/active_record"
3
- end
1
+ module Bsm::Sso::Client::Cached
2
+ autoload :ActiveRecord, "bsm/sso/client/cached/active_record"
3
+ end
@@ -1,50 +1,50 @@
1
- class Bsm::Sso::Client::User < Bsm::Sso::Client::AbstractResource
2
-
3
- class << self
4
-
5
- def all(options={})
6
- get("/users", options.reverse_merge(:expects => [200, 404, 422], :collection => true))
7
- end
8
-
9
- def sso_find(id)
10
- Bsm::Sso::Client.cache_store.fetch "users:#{id}", :expires_in => Bsm::Sso::Client.expire_after do
11
- get "/users/#{id}", :expects => [200, 404, 422]
12
- end
13
- end
14
-
15
- def sso_consume(ticket, service)
16
- get "/consume", :query => { :ticket => ticket, :service => service }
17
- end
18
-
19
- def sso_authorize(token)
20
- get "/authorize", :query => { :auth_token => token }
21
- end
22
-
23
- def sso_authenticate(credentials)
24
- get "/authenticate", :query => credentials.slice(:email, :password)
25
- end
26
-
27
- def sso_sign_in_url(params = {})
28
- sso_custom_absolute_method_root_url(:sign_in, params)
29
- end
30
-
31
- def sso_sign_out_url(params = {})
32
- sso_custom_absolute_method_root_url(:sign_out, params)
33
- end
34
-
35
- private
36
-
37
- def sso_custom_absolute_method_root_url(method_name, params = {})
38
- conn = site.data
39
- port = ""
40
- unless conn[:port].blank? || (conn[:scheme] == "http" && conn[:port].to_i == 80) || (conn[:scheme] == "https" && conn[:port].to_i == 443)
41
- port = ":#{conn[:port]}"
42
- end
43
-
44
- url = "#{conn[:scheme]}://#{conn[:host]}#{port}/#{method_name.to_s}"
45
- url << "?#{params.to_h.to_query}" unless params.empty?
46
- url
47
- end
48
-
49
- end
50
- end
1
+ class Bsm::Sso::Client::User < Bsm::Sso::Client::AbstractResource
2
+
3
+ class << self
4
+
5
+ def all(options={})
6
+ get("/users", options.reverse_merge(:expects => [200, 404, 422], :collection => true))
7
+ end
8
+
9
+ def sso_find(id)
10
+ Bsm::Sso::Client.cache_store.fetch "users:#{id}", :expires_in => Bsm::Sso::Client.expire_after do
11
+ get "/users/#{id}", :expects => [200, 404, 422]
12
+ end
13
+ end
14
+
15
+ def sso_consume(ticket, service)
16
+ get "/consume", :query => { :ticket => ticket, :service => service }
17
+ end
18
+
19
+ def sso_authorize(token)
20
+ get "/authorize", :query => { :auth_token => token }
21
+ end
22
+
23
+ def sso_authenticate(credentials)
24
+ get "/authenticate", :query => credentials.slice(:email, :password)
25
+ end
26
+
27
+ def sso_sign_in_url(params = {})
28
+ sso_custom_absolute_method_root_url(:sign_in, params)
29
+ end
30
+
31
+ def sso_sign_out_url(params = {})
32
+ sso_custom_absolute_method_root_url(:sign_out, params)
33
+ end
34
+
35
+ private
36
+
37
+ def sso_custom_absolute_method_root_url(method_name, params = {})
38
+ conn = site.data
39
+ port = ""
40
+ unless conn[:port].blank? || (conn[:scheme] == "http" && conn[:port].to_i == 80) || (conn[:scheme] == "https" && conn[:port].to_i == 443)
41
+ port = ":#{conn[:port]}"
42
+ end
43
+
44
+ url = "#{conn[:scheme]}://#{conn[:host]}#{port}/#{method_name.to_s}"
45
+ url << "?#{params.to_h.to_query}" unless params.empty?
46
+ url
47
+ end
48
+
49
+ end
50
+ end
@@ -1,38 +1,38 @@
1
- module Bsm::Sso::Client::UserMethods
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- class << self
6
- delegate :sso_sign_in_url, :sso_sign_out_url, :to => :"Bsm::Sso::Client::User"
7
- end
8
- end
9
-
10
- module ClassMethods
11
-
12
- def sso_find(id)
13
- resource = Bsm::Sso::Client::User.sso_find(id)
14
- sso_cache(resource, :find) if resource
15
- end
16
-
17
- def sso_consume(*a)
18
- resource = Bsm::Sso::Client::User.sso_consume(*a)
19
- sso_cache(resource, :consume) if resource
20
- end
21
-
22
- def sso_authenticate(*a)
23
- resource = Bsm::Sso::Client::User.sso_authenticate(*a)
24
- sso_cache(resource, :authenticate) if resource
25
- end
26
-
27
- def sso_authorize(*a)
28
- resource = Bsm::Sso::Client::User.sso_authorize(*a)
29
- sso_cache(resource, :authorize) if resource
30
- end
31
-
32
- def sso_cache(resource, action = nil)
33
- new(resource.attributes)
34
- end
35
-
36
- end
37
- end
38
-
1
+ module Bsm::Sso::Client::UserMethods
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ class << self
6
+ delegate :sso_sign_in_url, :sso_sign_out_url, :to => :"Bsm::Sso::Client::User"
7
+ end
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def sso_find(id)
13
+ resource = Bsm::Sso::Client::User.sso_find(id)
14
+ sso_cache(resource, :find) if resource
15
+ end
16
+
17
+ def sso_consume(*a)
18
+ resource = Bsm::Sso::Client::User.sso_consume(*a)
19
+ sso_cache(resource, :consume) if resource
20
+ end
21
+
22
+ def sso_authenticate(*a)
23
+ resource = Bsm::Sso::Client::User.sso_authenticate(*a)
24
+ sso_cache(resource, :authenticate) if resource
25
+ end
26
+
27
+ def sso_authorize(*a)
28
+ resource = Bsm::Sso::Client::User.sso_authorize(*a)
29
+ sso_cache(resource, :authorize) if resource
30
+ end
31
+
32
+ def sso_cache(resource, action = nil)
33
+ new(resource.attributes)
34
+ end
35
+
36
+ end
37
+ end
38
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsm-sso-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-08 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -78,20 +78,20 @@ dependencies:
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 0.27.0
81
+ version: 0.27.5
82
82
  - - "<"
83
83
  - !ruby/object:Gem::Version
84
- version: 1.0.0
84
+ version: '1'
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
90
90
  - !ruby/object:Gem::Version
91
- version: 0.27.0
91
+ version: 0.27.5
92
92
  - - "<"
93
93
  - !ruby/object:Gem::Version
94
- version: 1.0.0
94
+ version: '1'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: cancan
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -275,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
275
  version: '0'
276
276
  requirements: []
277
277
  rubyforge_project:
278
- rubygems_version: 2.6.8
278
+ rubygems_version: 2.7.7
279
279
  signing_key:
280
280
  specification_version: 4
281
281
  summary: BSM's internal SSO client