bsm-sso-client 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bsm/sso/client.rb +18 -0
- data/lib/bsm/sso/client/failure_app.rb +1 -3
- data/lib/bsm/sso/client/strategies.rb +1 -0
- data/lib/bsm/sso/client/strategies/api_token.rb +47 -0
- data/lib/bsm/sso/client/strategies/base.rb +4 -0
- data/lib/bsm/sso/client/strategies/http_auth.rb +1 -1
- data/lib/bsm/sso/client/strategies/ticket.rb +1 -1
- metadata +25 -24
data/lib/bsm/sso/client.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
require 'rails'
|
2
|
+
require 'active_support/message_verifier'
|
3
|
+
require 'active_support/memoizable'
|
4
|
+
require 'active_support/core_ext/object/acts_like'
|
5
|
+
require 'active_support/core_ext/time/acts_like'
|
6
|
+
require 'active_support/core_ext/date_time/acts_like'
|
2
7
|
require 'active_support/core_ext/numeric/time'
|
3
8
|
require 'active_support/dependencies'
|
4
9
|
require 'active_resource'
|
@@ -26,9 +31,18 @@ module Bsm
|
|
26
31
|
mattr_writer :user_class
|
27
32
|
@@user_class = nil
|
28
33
|
|
34
|
+
mattr_accessor :user_attributes
|
35
|
+
@@user_attributes = {}
|
36
|
+
|
29
37
|
mattr_accessor :warden_configuration
|
30
38
|
@@warden_configuration = nil
|
31
39
|
|
40
|
+
mattr_reader :navigational_formats
|
41
|
+
@@navigational_formats = [:html, :all, :js, nil].to_set
|
42
|
+
|
43
|
+
mattr_reader :api_formats
|
44
|
+
@@api_formats = [:xml, :json].to_set
|
45
|
+
|
32
46
|
class << self
|
33
47
|
|
34
48
|
delegate :site=, :site, :to => :"Bsm::Sso::Client::AbstractResource"
|
@@ -37,6 +51,10 @@ module Bsm
|
|
37
51
|
@@user_class || Bsm::Sso::Client::User
|
38
52
|
end
|
39
53
|
|
54
|
+
def user_instance
|
55
|
+
user_class.new(user_attributes)
|
56
|
+
end
|
57
|
+
|
40
58
|
# Default message verifier
|
41
59
|
def verifier
|
42
60
|
raise "Please configure a secret! Example: Bsm::Sso::Client.secret = '...'" unless secret.present?
|
@@ -3,8 +3,6 @@ class Bsm::Sso::Client::FailureApp < ActionController::Metal
|
|
3
3
|
include ActionController::Redirecting
|
4
4
|
include Bsm::Sso::Client::UrlHelpers
|
5
5
|
|
6
|
-
NAVIGATIONAL_FORMATS = [:html, :all, :js, nil].to_set.freeze
|
7
|
-
|
8
6
|
def self.call(env)
|
9
7
|
action(:respond).call(env)
|
10
8
|
end
|
@@ -14,7 +12,7 @@ class Bsm::Sso::Client::FailureApp < ActionController::Metal
|
|
14
12
|
end
|
15
13
|
|
16
14
|
def respond
|
17
|
-
if
|
15
|
+
if Bsm::Sso::Client.navigational_formats.include?(request.format.try(:to_sym))
|
18
16
|
request.xhr? ? respond_with_js! : redirect!
|
19
17
|
else
|
20
18
|
stop!
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Bsm::Sso::Client::Strategies::APIToken < Bsm::Sso::Client::Strategies::HttpAuth
|
2
|
+
extend ActiveSupport::Memoizable
|
3
|
+
|
4
|
+
def self.verifier
|
5
|
+
@verifier ||= ActiveSupport::MessageVerifier.new(secret)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.secret=(value)
|
9
|
+
@verifier = nil
|
10
|
+
@secret = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.secret
|
14
|
+
Bsm::Sso::Client.secret
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.user_instance
|
18
|
+
Bsm::Sso::Client.user_instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_format?
|
22
|
+
Bsm::Sso::Client.api_formats.include? request.format.try(:to_sym)
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid?
|
26
|
+
api_format? && super && !!expiration
|
27
|
+
end
|
28
|
+
|
29
|
+
def authenticate!
|
30
|
+
if expiration >= Time.now
|
31
|
+
success!(user_instance)
|
32
|
+
else
|
33
|
+
fail!(:expired)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def expiration
|
38
|
+
result = self.class.verifier.verify(token)
|
39
|
+
result if result.acts_like?(:time)
|
40
|
+
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
memoize :expiration
|
44
|
+
|
45
|
+
Warden::Strategies.add :sso_api_token, self
|
46
|
+
end
|
47
|
+
|
@@ -18,6 +18,6 @@ class Bsm::Sso::Client::Strategies::HttpAuth < Bsm::Sso::Client::Strategies::Bas
|
|
18
18
|
@token ||= ActiveSupport::Base64.decode64($1).split(/:/, 2).first
|
19
19
|
end
|
20
20
|
|
21
|
+
Warden::Strategies.add :sso_http_auth, self
|
21
22
|
end
|
22
23
|
|
23
|
-
Warden::Strategies.add :sso_http_auth, Bsm::Sso::Client::Strategies::HttpAuth
|
@@ -10,7 +10,7 @@ class Bsm::Sso::Client::Strategies::Ticket < Bsm::Sso::Client::Strategies::Base
|
|
10
10
|
u.nil? ? fail!(:invalid) : success!(u)
|
11
11
|
end
|
12
12
|
|
13
|
+
Warden::Strategies.add :sso_ticket, self
|
13
14
|
end
|
14
15
|
|
15
|
-
Warden::Strategies.add :sso_ticket, Bsm::Sso::Client::Strategies::Ticket
|
16
16
|
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|
16
|
-
requirement: &
|
16
|
+
requirement: &18232380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: 3.2.0
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *18232380
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: actionpack
|
30
|
-
requirement: &
|
30
|
+
requirement: &18230600 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ! '>='
|
@@ -38,10 +38,10 @@ dependencies:
|
|
38
38
|
version: 3.2.0
|
39
39
|
type: :runtime
|
40
40
|
prerelease: false
|
41
|
-
version_requirements: *
|
41
|
+
version_requirements: *18230600
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: railties
|
44
|
-
requirement: &
|
44
|
+
requirement: &18229320 !ruby/object:Gem::Requirement
|
45
45
|
none: false
|
46
46
|
requirements:
|
47
47
|
- - ! '>='
|
@@ -52,10 +52,10 @@ dependencies:
|
|
52
52
|
version: 3.2.0
|
53
53
|
type: :runtime
|
54
54
|
prerelease: false
|
55
|
-
version_requirements: *
|
55
|
+
version_requirements: *18229320
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rails_warden
|
58
|
-
requirement: &
|
58
|
+
requirement: &18228180 !ruby/object:Gem::Requirement
|
59
59
|
none: false
|
60
60
|
requirements:
|
61
61
|
- - ~>
|
@@ -63,10 +63,10 @@ dependencies:
|
|
63
63
|
version: 0.5.0
|
64
64
|
type: :runtime
|
65
65
|
prerelease: false
|
66
|
-
version_requirements: *
|
66
|
+
version_requirements: *18228180
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: activerecord
|
69
|
-
requirement: &
|
69
|
+
requirement: &18227620 !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
72
72
|
- - ! '>='
|
@@ -74,10 +74,10 @@ dependencies:
|
|
74
74
|
version: '0'
|
75
75
|
type: :development
|
76
76
|
prerelease: false
|
77
|
-
version_requirements: *
|
77
|
+
version_requirements: *18227620
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: rake
|
80
|
-
requirement: &
|
80
|
+
requirement: &18223100 !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
83
|
- - ! '>='
|
@@ -85,10 +85,10 @@ dependencies:
|
|
85
85
|
version: '0'
|
86
86
|
type: :development
|
87
87
|
prerelease: false
|
88
|
-
version_requirements: *
|
88
|
+
version_requirements: *18223100
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rack-test
|
91
|
-
requirement: &
|
91
|
+
requirement: &18222520 !ruby/object:Gem::Requirement
|
92
92
|
none: false
|
93
93
|
requirements:
|
94
94
|
- - ! '>='
|
@@ -96,10 +96,10 @@ dependencies:
|
|
96
96
|
version: '0'
|
97
97
|
type: :development
|
98
98
|
prerelease: false
|
99
|
-
version_requirements: *
|
99
|
+
version_requirements: *18222520
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
101
|
name: rspec
|
102
|
-
requirement: &
|
102
|
+
requirement: &18221920 !ruby/object:Gem::Requirement
|
103
103
|
none: false
|
104
104
|
requirements:
|
105
105
|
- - ! '>='
|
@@ -107,10 +107,10 @@ dependencies:
|
|
107
107
|
version: '0'
|
108
108
|
type: :development
|
109
109
|
prerelease: false
|
110
|
-
version_requirements: *
|
110
|
+
version_requirements: *18221920
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: shoulda-matchers
|
113
|
-
requirement: &
|
113
|
+
requirement: &18221380 !ruby/object:Gem::Requirement
|
114
114
|
none: false
|
115
115
|
requirements:
|
116
116
|
- - ! '>='
|
@@ -118,10 +118,10 @@ dependencies:
|
|
118
118
|
version: '0'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
|
-
version_requirements: *
|
121
|
+
version_requirements: *18221380
|
122
122
|
- !ruby/object:Gem::Dependency
|
123
123
|
name: webmock
|
124
|
-
requirement: &
|
124
|
+
requirement: &18220740 !ruby/object:Gem::Requirement
|
125
125
|
none: false
|
126
126
|
requirements:
|
127
127
|
- - ! '>='
|
@@ -129,10 +129,10 @@ dependencies:
|
|
129
129
|
version: '0'
|
130
130
|
type: :development
|
131
131
|
prerelease: false
|
132
|
-
version_requirements: *
|
132
|
+
version_requirements: *18220740
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
134
|
name: sqlite3-ruby
|
135
|
-
requirement: &
|
135
|
+
requirement: &18220100 !ruby/object:Gem::Requirement
|
136
136
|
none: false
|
137
137
|
requirements:
|
138
138
|
- - ! '>='
|
@@ -140,7 +140,7 @@ dependencies:
|
|
140
140
|
version: '0'
|
141
141
|
type: :development
|
142
142
|
prerelease: false
|
143
|
-
version_requirements: *
|
143
|
+
version_requirements: *18220100
|
144
144
|
description: ''
|
145
145
|
email: dimitrij@blacksquaremedia.com
|
146
146
|
executables: []
|
@@ -148,6 +148,7 @@ extensions: []
|
|
148
148
|
extra_rdoc_files: []
|
149
149
|
files:
|
150
150
|
- lib/bsm/sso/client.rb
|
151
|
+
- lib/bsm/sso/client/strategies/api_token.rb
|
151
152
|
- lib/bsm/sso/client/strategies/ticket.rb
|
152
153
|
- lib/bsm/sso/client/strategies/base.rb
|
153
154
|
- lib/bsm/sso/client/strategies/http_auth.rb
|