rails_sso 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26aee36b2cf776c7887e8076d19fb8a06ee868f1
4
- data.tar.gz: 1b2d7f063181a77747f38479578cfae1ef43b350
3
+ metadata.gz: 67bfc750650c80d246439d2f943919bd88399638
4
+ data.tar.gz: 96a12fb1c25b4873344326c3b1afec95dcc991e7
5
5
  SHA512:
6
- metadata.gz: d3e99e4f290a9c6158b76b043e7ced982a7e8745914d9d550d3f72c1e3384b95416023016122a64631c37ebcf6e9aaa629d8250e73330077485aae50c5d00d6c
7
- data.tar.gz: 2af36a116a0f166d01c5a5240be0bd78d6993b05927e522f84794981d30304f2d04db3e0cbbeeee995c1219910e0e62beb32d8236e19a5694e643c1e2ecbb364
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
- OmniAuth.config.test_mode = true
98
+ RailsSso.configure do
99
+ config.test_mode = true
100
+ end
90
101
  ```
91
102
 
92
- To mock user data use OmniAuth `mock_auth` feature with your provider.
103
+ Mock data should be passed to `profile_mock` configuration.
93
104
 
94
105
  ```ruby
95
- OmniAuth.config.mock_auth[:example] = OmniAuth::AuthHash.new({
96
- name: 'John Kowalski',
97
- uid: '42'
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 mock_token if OmniAuth.config.test_mode
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 OmniAuth.config.test_mode
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, {}, mock_auth] }
73
+ stub.get(RailsSso.provider_profile_path) { |env| [200, {}, profile_mock] }
74
74
  end
75
75
  end
76
76
 
77
- def mock_auth
78
- OmniAuth.config.mock_auth[RailsSso.provider_name.to_sym].to_json
77
+ def profile_mock
78
+ RailsSso.profile_mock.to_json
79
79
  end
80
80
 
81
- def mock_token
81
+ def token_mock
82
82
  RailsSso::TokenMock.new
83
83
  end
84
84
  end
@@ -41,7 +41,7 @@ module RailsSso
41
41
 
42
42
  app.config.middleware.insert_after OmniAuth::Builder, Warden::Manager do |manager|
43
43
  manager.default_strategies :sso
44
- manager.failure_app = RailsSso::FailureApp
44
+ manager.failure_app = RailsSso.failure_app
45
45
  end
46
46
  end
47
47
  end
@@ -9,7 +9,13 @@ module RailsSso
9
9
  end
10
10
 
11
11
  def respond
12
- redirect_to sign_in_path
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
@@ -1,3 +1,3 @@
1
1
  module RailsSso
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
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
- @@use_cache = false
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'