omniauth-icalia 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cad58273fb22cba6b5c8d71664759576620fa2537740fdfccde10cb60f2fff0
4
- data.tar.gz: 7e276c2f58291e30add46bebb595658afddc43e6b2c7d06f21aa7096b726b68e
3
+ metadata.gz: 4dfbfb47218190adfbee66c478cf9787d52b5de4ccea2f9d325c415553ed3ec8
4
+ data.tar.gz: 775e1514daa1c195234328daf2534a90b773f3ce27f75e390d743e03791b069a
5
5
  SHA512:
6
- metadata.gz: 0aca0652ac4f348489ad9486182bdb3cee95c926c307865aa0a9d91b2c84287c5fe2b562dc46f76857a542ef0b256d2a433fbdcc4544b2b3c979dd6baef3845d
7
- data.tar.gz: 469abd58dd314111be50a440e7055d3939c3b1b133b25ebc13e46ea04549dd8aae48d63ed274b299f1993fc9ff246f6d6ac681678257601af3c39475a657f68b
6
+ metadata.gz: 478333a7b552a4961d892e3088b8a86755743605124d8aed6897bfb366c3aadd6a93b205cf565ddbaf30d1ff4f5dd2f3a0c7ae587e839ab796ec45382fb50dcb
7
+ data.tar.gz: 2dd160af460ee9a27f54efca2e702ab2b3e3c86d571e8235ef301dfb3c40c938bdab3596b531289e69e15611f04ac48b983dc6114c34267657298335eaa84b36
data/README.md CHANGED
@@ -51,6 +51,35 @@ before do
51
51
  end
52
52
  ```
53
53
 
54
+ If your'e testing a sign-in flow:
55
+
56
+ ```ruby
57
+ scenario 'sign-in' do
58
+ # Simulate that the user will sign-in at the SSO site:
59
+ Icalia::StubbedSSOService.sign_in_on_authorize
60
+ visit root_path # or any path in your app that requires authentication
61
+
62
+ #...
63
+ end
64
+ ```
65
+
66
+ If your'e testing a sign-out flow:
67
+
68
+ ```ruby
69
+ scenario 'sign-out' do
70
+ # Simulate that the user will sign-in at the SSO site:
71
+ Icalia::StubbedSSOService.sign_in_on_authorize
72
+ visit root_path # or any path in your app that requires authentication
73
+
74
+ # Simulate that the user won't sign-in at the SSO site:
75
+ Icalia::StubbedSSOService.do_not_sign_in_on_authorize
76
+ click_link 'Logout'
77
+
78
+ # The message coming from Artanis & the Fake Artanis "StubbedSSOService":
79
+ expect(page).to have_content 'Signed out successfully.'
80
+ end
81
+ ```
82
+
54
83
  ## Development
55
84
 
56
85
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -10,6 +10,8 @@ module Icalia
10
10
  FIND_AVAILABLE_PORT = 0
11
11
  CODE = 'icalia_oauth_authorization_code'.freeze
12
12
 
13
+ @@sign_in_user_on_authorize = false
14
+
13
15
  post '/oauth/token' do
14
16
  if params[:code] == CODE
15
17
  response.headers['Content-Type'] = 'application/json'
@@ -30,7 +32,18 @@ module Icalia
30
32
  end
31
33
  end
32
34
 
35
+ get '/sign-in' do
36
+ 'Signed out successfully.'
37
+ end
38
+
39
+ get '/sign-out' do
40
+ uri = URI(params[:redirect_uri])
41
+ redirect uri
42
+ end
43
+
33
44
  get '/oauth/authorize' do
45
+ return redirect '/sign-in' unless @@sign_in_user_on_authorize
46
+
34
47
  store_oauth_flow_data params
35
48
  uri = URI(params[:redirect_uri])
36
49
  uri.query = URI.encode_www_form(state: params[:state], code: CODE)
@@ -116,37 +129,53 @@ module Icalia
116
129
  def store_oauth_flow_data(data)
117
130
  oauth_flows << data
118
131
  end
132
+
133
+ def url
134
+ "http://localhost:#{server_port}"
135
+ end
136
+
137
+ def sign_in_url
138
+ "#{url}/sign-in"
139
+ end
119
140
 
120
141
  # Taken from FakeStripe.stub_stripe at fake_stripe gem:
121
142
  def prepare
122
143
  reset
123
-
144
+
124
145
  yield self if block_given?
125
-
146
+
126
147
  # Since the OAuth flow is performed by the browser, we'll need to boot
127
148
  # the Sinatra app instead of just stubbing the app with WebMock...
128
149
  boot_once
129
-
130
- oauth_host = "http://localhost:#{server_port}"
131
150
 
132
- OmniAuth::Strategies::Icalia.instances.each do |options|
133
- client_options = options.client_options
134
- client_options.site = oauth_host
135
- client_options.token_url = "#{oauth_host}/oauth/token"
136
- client_options.authorize_url = "#{oauth_host}/oauth/authorize"
151
+ OmniAuth::Strategies::Icalia.instances.each do |strategy|
152
+ strategy.options.client_options.tap do |options|
153
+ options.site = url
154
+ options.token_url = "#{oauth_host}/oauth/token"
155
+ options.authorize_url = "#{oauth_host}/oauth/authorize"
156
+ end
137
157
  end
138
158
  end
139
159
 
160
+ def sign_in_on_authorize
161
+ @@sign_in_user_on_authorize = true
162
+ end
163
+
164
+ def do_not_sign_in_on_authorize
165
+ @@sign_in_user_on_authorize = false
166
+ end
167
+
140
168
  def teardown
141
169
  default_client_options = OmniAuth::Strategies::Icalia
142
170
  .default_options
143
171
  .client_options
144
-
145
- OmniAuth::Strategies::Icalia.instances.each do |options|
146
- client_options = options.client_options
147
- client_options.site = default_client_options.site
148
- client_options.token_url = default_client_options.token_url
149
- client_options.authorize_url = default_client_options.authorize_url
172
+
173
+ OmniAuth::Strategies::Icalia.instances.each do |strategy|
174
+ strategy.options.client_options.tap do |options|
175
+ options.site = default_client_options.site
176
+ options.token_url = default_client_options.token_url
177
+ options.authorize_url = default_client_options.authorize_url
178
+ end
150
179
  end
151
180
  end
152
181
 
@@ -1,5 +1,5 @@
1
1
  module Omniauth
2
2
  module Icalia
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
@@ -19,9 +19,9 @@ module OmniAuth
19
19
  end
20
20
 
21
21
  def initialize(*args)
22
- instance = super(*args)
23
- @@instances << instance
24
- instance
22
+ ret = super
23
+ @@instances << self
24
+ ret
25
25
  end
26
26
 
27
27
  def request_phase
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-icalia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Quintanilla
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2020-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth