bsm-sso-client 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bsm/sso/client.rb +0 -1
- data/lib/bsm/sso/client/abstract_resource.rb +65 -4
- data/lib/bsm/sso/client/user.rb +14 -11
- metadata +24 -8
data/lib/bsm/sso/client.rb
CHANGED
@@ -6,7 +6,6 @@ require 'active_support/core_ext/time/acts_like'
|
|
6
6
|
require 'active_support/core_ext/date_time/acts_like'
|
7
7
|
require 'active_support/core_ext/numeric/time'
|
8
8
|
require 'active_support/dependencies'
|
9
|
-
require 'active_resource'
|
10
9
|
require 'action_controller'
|
11
10
|
require 'action_controller/metal/exceptions'
|
12
11
|
require 'rails_warden'
|
@@ -1,12 +1,73 @@
|
|
1
|
-
|
2
|
-
|
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
|
3
7
|
|
4
8
|
class << self
|
5
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
|
6
24
|
def headers
|
7
|
-
{ '
|
25
|
+
{ 'Authorization' => Bsm::Sso::Client.verifier.generate(30.seconds.from_now) }
|
8
26
|
end
|
9
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 = params.merge(:path => path)
|
33
|
+
params[:headers] = (params[:headers] || {}).merge(headers)
|
34
|
+
response = site.get(params)
|
35
|
+
return nil unless response.status == 200
|
36
|
+
|
37
|
+
instance = new ActiveSupport::JSON.decode(response.body)
|
38
|
+
instance if instance.id
|
39
|
+
rescue MultiJson::DecodeError
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# Constuctor
|
46
|
+
# @param [Hash,NilClass] attributes the attributes to assign
|
47
|
+
def initialize(attributes = nil)
|
48
|
+
super()
|
49
|
+
update(attributes.stringify_keys) if attributes.is_a?(Hash)
|
10
50
|
end
|
11
|
-
end
|
12
51
|
|
52
|
+
# @return [Integer] ID, the primary key
|
53
|
+
def id
|
54
|
+
self["id"]
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Boolean] true, if method exists?
|
58
|
+
def respond_to?(method, *)
|
59
|
+
super || key?(method.to_s)
|
60
|
+
end
|
61
|
+
|
62
|
+
# @return [Hash] attributes hash
|
63
|
+
def attributes
|
64
|
+
dup
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def method_missing(method, *)
|
70
|
+
key?(method.to_s) ? fetch(method.to_s) : super
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/lib/bsm/sso/client/user.rb
CHANGED
@@ -1,28 +1,23 @@
|
|
1
1
|
class Bsm::Sso::Client::User < Bsm::Sso::Client::AbstractResource
|
2
|
+
|
2
3
|
class << self
|
3
4
|
|
4
5
|
def sso_find(id)
|
5
6
|
Bsm::Sso::Client.cache_store.fetch "users:#{id}", :expires_in => Bsm::Sso::Client.expire_after do
|
6
|
-
|
7
|
+
get "/users/#{id}", :expects => [200, 404, 422]
|
7
8
|
end
|
8
9
|
end
|
9
10
|
|
10
11
|
def sso_consume(ticket, service)
|
11
|
-
|
12
|
-
rescue ActiveResource::ResourceInvalid
|
13
|
-
nil
|
12
|
+
get "/consume", :query => { :ticket => ticket, :service => service }
|
14
13
|
end
|
15
14
|
|
16
15
|
def sso_authorize(token)
|
17
|
-
|
18
|
-
rescue ActiveResource::ResourceInvalid
|
19
|
-
nil
|
16
|
+
get "/authorize", :query => { :auth_token => token }
|
20
17
|
end
|
21
18
|
|
22
19
|
def sso_authenticate(credentials)
|
23
|
-
|
24
|
-
rescue ActiveResource::ResourceInvalid
|
25
|
-
nil
|
20
|
+
get "/authenticate", :query => credentials.slice(:email, :password)
|
26
21
|
end
|
27
22
|
|
28
23
|
def sso_sign_in_url(params = {})
|
@@ -36,7 +31,15 @@ class Bsm::Sso::Client::User < Bsm::Sso::Client::AbstractResource
|
|
36
31
|
private
|
37
32
|
|
38
33
|
def sso_custom_absolute_method_root_url(method_name, params = {})
|
39
|
-
|
34
|
+
conn = site.connection
|
35
|
+
port = ""
|
36
|
+
unless conn[:port].blank? || (conn[:scheme] == "http" && conn[:port].to_i == 80) || (conn[:scheme] == "https" && conn[:port].to_i == 443)
|
37
|
+
port = ":#{conn[:port]}"
|
38
|
+
end
|
39
|
+
|
40
|
+
url = "#{conn[:scheme]}://#{conn[:host]}#{port}/#{method_name.to_s}"
|
41
|
+
url << "?#{params.to_query}" unless params.empty?
|
42
|
+
url
|
40
43
|
end
|
41
44
|
|
42
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bsm-sso-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: railties
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: '0'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,15 +42,15 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: activesupport
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: '0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: rails_warden
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 0.5.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: excon
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.14.0
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.14.0
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: activerecord
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|