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 +5 -5
- data/lib/bsm/sso/client.rb +1 -1
- data/lib/bsm/sso/client/abstract_resource.rb +90 -89
- data/lib/bsm/sso/client/cached.rb +3 -3
- data/lib/bsm/sso/client/user.rb +50 -50
- data/lib/bsm/sso/client/user_methods.rb +38 -38
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e2130651c34cb85c562ab688d121eed6f6d709c002ca6388d9a6742b19f2e134
|
4
|
+
data.tar.gz: 6fd1a90fb066f52d007086f30e5d2590639f3df17c4994b50bb1dbd89d6e7a3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37811dc50112157d7ca226004bebd51f9ebdd77e7986d173bdaa7509ce88a7447bf17fa01f9a401bae8d0a04563e399a2eaabf34c2fe3512f0fff81a8da9d698
|
7
|
+
data.tar.gz: 3e84ae2f5bbbc07f2c7f990f957abd2944e7b123d779f7f6c38701f4a2b50ea07e63c81dc10ce49a21a9e76e8642783b1964ceb33f50391342918fca8a831d48
|
data/lib/bsm/sso/client.rb
CHANGED
@@ -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
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# @param [
|
30
|
-
# @
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
params
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
result =
|
42
|
-
|
43
|
-
instance
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
data/lib/bsm/sso/client/user.rb
CHANGED
@@ -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.
|
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:
|
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.
|
81
|
+
version: 0.27.5
|
82
82
|
- - "<"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: 1
|
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.
|
91
|
+
version: 0.27.5
|
92
92
|
- - "<"
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: 1
|
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.
|
278
|
+
rubygems_version: 2.7.7
|
279
279
|
signing_key:
|
280
280
|
specification_version: 4
|
281
281
|
summary: BSM's internal SSO client
|