rails_sso 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -7
- data/lib/rails_sso/app.rb +6 -6
- data/lib/rails_sso/engine.rb +1 -1
- data/lib/rails_sso/failure_app.rb +7 -1
- data/lib/rails_sso/version.rb +1 -1
- data/lib/rails_sso.rb +16 -2
- data/test/dummy/log/test.log +1242 -0
- data/test/lib/rails_sso/failure_app_test.rb +12 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67bfc750650c80d246439d2f943919bd88399638
|
4
|
+
data.tar.gz: 96a12fb1c25b4873344326c3b1afec95dcc991e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8ea2ac967c2e0d475467925b50cf64701afb94c13611419fec28337dd2a18ac0f1b1ff9662a8fa0dfc8123f2a1c97d4ca5d518a49f6523e2bf44ce8777621f6
|
7
|
+
data.tar.gz: a42f6e604d5ccb8f88bbc7688814a874c9d5c597034a1a64ef5cf5dabdea4fbf4dd7a12f33a0ca044c972c0f40250957597e63182139f32fec3b9f8aa48fcaa5
|
data/README.md
CHANGED
@@ -48,6 +48,15 @@ RailsSso.configure do |config|
|
|
48
48
|
config.provider_sign_out_path = '/api/v1/session'
|
49
49
|
# enable cache (will use Rails.cache store)
|
50
50
|
config.use_cache = Rails.application.config.action_controller.perform_caching
|
51
|
+
# test & development mode
|
52
|
+
config.test_mode = ENV['mock_sso']
|
53
|
+
config.profile_mock = {
|
54
|
+
user: 'John Blacksmith',
|
55
|
+
uid: '169783'
|
56
|
+
}
|
57
|
+
# custom failure app
|
58
|
+
# more: https://github.com/hassox/warden/wiki/Failures
|
59
|
+
config.failure_app = MyFailureApp
|
51
60
|
end
|
52
61
|
```
|
53
62
|
|
@@ -83,19 +92,23 @@ Available helpers for views:
|
|
83
92
|
|
84
93
|
## Testing & Development mode
|
85
94
|
|
86
|
-
You can turn on "test mode" by enabling [OmniAuth test mode](https://github.com/intridea/omniauth/wiki/Integration-Testing).
|
95
|
+
You can turn on "test mode" by enabling test mode. It will also automatically enable [OmniAuth test mode](https://github.com/intridea/omniauth/wiki/Integration-Testing).
|
87
96
|
|
88
97
|
```ruby
|
89
|
-
|
98
|
+
RailsSso.configure do
|
99
|
+
config.test_mode = true
|
100
|
+
end
|
90
101
|
```
|
91
102
|
|
92
|
-
|
103
|
+
Mock data should be passed to `profile_mock` configuration.
|
93
104
|
|
94
105
|
```ruby
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
106
|
+
RailsSso.configure do |config|
|
107
|
+
config.profile_mock = {
|
108
|
+
name: 'John Kowalski',
|
109
|
+
uid: '42'
|
110
|
+
}
|
111
|
+
end
|
99
112
|
```
|
100
113
|
|
101
114
|
## Contributing
|
data/lib/rails_sso/app.rb
CHANGED
@@ -30,7 +30,7 @@ module RailsSso
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def access_token
|
33
|
-
return
|
33
|
+
return token_mock if RailsSso.test_mode
|
34
34
|
|
35
35
|
OAuth2::AccessToken.new(strategy.client, session[:access_token], {
|
36
36
|
refresh_token: session[:refresh_token]
|
@@ -46,7 +46,7 @@ module RailsSso
|
|
46
46
|
def provider_client
|
47
47
|
@provider_client ||= RailsSso::Client.new(RailsSso.provider_url) do |conn|
|
48
48
|
case
|
49
|
-
when
|
49
|
+
when RailsSso.test_mode
|
50
50
|
mock_connection(conn)
|
51
51
|
else
|
52
52
|
setup_connection(conn)
|
@@ -70,15 +70,15 @@ module RailsSso
|
|
70
70
|
|
71
71
|
def mock_connection(conn)
|
72
72
|
conn.adapter :test do |stub|
|
73
|
-
stub.get(RailsSso.provider_profile_path) { |env| [200, {},
|
73
|
+
stub.get(RailsSso.provider_profile_path) { |env| [200, {}, profile_mock] }
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
78
|
-
|
77
|
+
def profile_mock
|
78
|
+
RailsSso.profile_mock.to_json
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
81
|
+
def token_mock
|
82
82
|
RailsSso::TokenMock.new
|
83
83
|
end
|
84
84
|
end
|
data/lib/rails_sso/engine.rb
CHANGED
@@ -9,7 +9,13 @@ module RailsSso
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def respond
|
12
|
-
|
12
|
+
if request.content_type == 'application/json'
|
13
|
+
self.status = :unauthorized
|
14
|
+
self.content_type = request.content_type
|
15
|
+
self.response_body = ''
|
16
|
+
else
|
17
|
+
redirect_to sign_in_path
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/rails_sso/version.rb
CHANGED
data/lib/rails_sso.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module RailsSso
|
2
2
|
mattr_accessor :application_controller
|
3
|
-
@@application_controller = 'ApplicationController'
|
4
3
|
|
5
4
|
mattr_accessor :provider_url
|
6
5
|
mattr_accessor :provider_name
|
@@ -11,9 +10,19 @@ module RailsSso
|
|
11
10
|
mattr_accessor :provider_sign_out_path
|
12
11
|
|
13
12
|
mattr_accessor :use_cache
|
14
|
-
|
13
|
+
|
14
|
+
mattr_accessor :test_mode
|
15
|
+
mattr_accessor :profile_mock
|
16
|
+
|
17
|
+
mattr_accessor :failure_app
|
15
18
|
|
16
19
|
def self.configure
|
20
|
+
self.application_controller = 'ApplicationController'
|
21
|
+
self.use_cache = false
|
22
|
+
self.test_mode = false
|
23
|
+
self.profile_mock = {}
|
24
|
+
self.failure_app = RailsSso::FailureApp
|
25
|
+
|
17
26
|
yield self
|
18
27
|
end
|
19
28
|
|
@@ -28,6 +37,11 @@ module RailsSso
|
|
28
37
|
def self.oauth2_strategy_class
|
29
38
|
OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(provider_name.to_s)}")
|
30
39
|
end
|
40
|
+
|
41
|
+
def self.test_mode=(value)
|
42
|
+
@@test_mode = value
|
43
|
+
OmniAuth.config.test_mode = value
|
44
|
+
end
|
31
45
|
end
|
32
46
|
|
33
47
|
require 'warden'
|