Skip to content

Commit 6b4509f

Browse files
pontiphexjeffreyolio
authored andcommitted
Adds ext- params to /authorize redirect logic
1 parent e3e0a0b commit 6b4509f

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

lib/omniauth/strategies/auth0.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ def client
8484
# Define the parameters used for the /authorize endpoint
8585
def authorize_params
8686
params = super
87-
%w[connection connection_scope prompt screen_hint login_hint organization invitation ui_locales].each do |key|
88-
params[key] = request.params[key] if request.params.key?(key)
89-
end
87+
88+
params.merge! request.params.select{|k,b| is_authorized_param?(k)}
9089

9190
# Generate nonce
9291
params[:nonce] = SecureRandom.hex
@@ -128,6 +127,12 @@ def callback_phase
128127
end
129128

130129
private
130+
def is_authorized_param?(param_key)
131+
authorized_keys = %w[connection connection_scope prompt screen_hint login_hint organization invitation ui_locales]
132+
133+
param_key.start_with?("ext-") || authorized_keys.include?(param_key)
134+
end
135+
131136
def jwt_validator
132137
@jwt_validator ||= OmniAuth::Auth0::JWTValidator.new(options)
133138
end

spec/omniauth/strategies/auth0_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
expect(redirect_url).not_to have_query('auth0Client')
9393
expect(redirect_url).not_to have_query('connection')
9494
expect(redirect_url).not_to have_query('connection_scope')
95+
expect(redirect_url).not_to have_query('ext-test')
9596
expect(redirect_url).not_to have_query('prompt')
9697
expect(redirect_url).not_to have_query('screen_hint')
9798
expect(redirect_url).not_to have_query('login_hint')
@@ -111,6 +112,7 @@
111112
expect(redirect_url).to have_query('connection', 'abcd')
112113
expect(redirect_url).not_to have_query('auth0Client')
113114
expect(redirect_url).not_to have_query('connection_scope')
115+
expect(redirect_url).not_to have_query('ext-test')
114116
expect(redirect_url).not_to have_query('prompt')
115117
expect(redirect_url).not_to have_query('screen_hint')
116118
expect(redirect_url).not_to have_query('login_hint')
@@ -139,6 +141,7 @@
139141
expect(redirect_url).to have_query('prompt', 'login')
140142
expect(redirect_url).not_to have_query('auth0Client')
141143
expect(redirect_url).not_to have_query('connection')
144+
expect(redirect_url).not_to have_query('ext-test')
142145
expect(redirect_url).not_to have_query('login_hint')
143146
expect(redirect_url).not_to have_query('organization')
144147
expect(redirect_url).not_to have_query('invitation')
@@ -156,6 +159,7 @@
156159
expect(redirect_url).to have_query('screen_hint', 'signup')
157160
expect(redirect_url).not_to have_query('auth0Client')
158161
expect(redirect_url).not_to have_query('connection')
162+
expect(redirect_url).not_to have_query('ext-test')
159163
expect(redirect_url).not_to have_query('login_hint')
160164
expect(redirect_url).not_to have_query('organization')
161165
expect(redirect_url).not_to have_query('invitation')
@@ -175,6 +179,7 @@
175179
expect(redirect_url).not_to have_query('auth0Client')
176180
expect(redirect_url).not_to have_query('connection')
177181
expect(redirect_url).not_to have_query('connection_scope')
182+
expect(redirect_url).not_to have_query('ext-test')
178183
expect(redirect_url).not_to have_query('prompt')
179184
expect(redirect_url).not_to have_query('screen_hint')
180185
expect(redirect_url).not_to have_query('login_hint')
@@ -193,6 +198,27 @@
193198
expect(redirect_url).not_to have_query('auth0Client')
194199
expect(redirect_url).not_to have_query('connection')
195200
expect(redirect_url).not_to have_query('connection_scope')
201+
expect(redirect_url).not_to have_query('ext-test')
202+
expect(redirect_url).not_to have_query('prompt')
203+
expect(redirect_url).not_to have_query('screen_hint')
204+
expect(redirect_url).not_to have_query('organization')
205+
expect(redirect_url).not_to have_query('invitation')
206+
end
207+
208+
it 'redirects to hosted login page with ext-test=testval' do
209+
get 'auth/auth0?ext-test=testval'
210+
expect(last_response.status).to eq(302)
211+
redirect_url = last_response.headers['Location']
212+
expect(redirect_url).to start_with('https://samples.auth0.com/authorize')
213+
expect(redirect_url).to have_query('response_type', 'code')
214+
expect(redirect_url).to have_query('state')
215+
expect(redirect_url).to have_query('client_id')
216+
expect(redirect_url).to have_query('redirect_uri')
217+
expect(redirect_url).to have_query('ext-test', 'testval')
218+
expect(redirect_url).not_to have_query('auth0Client')
219+
expect(redirect_url).not_to have_query('connection')
220+
expect(redirect_url).not_to have_query('connection_scope')
221+
expect(redirect_url).not_to have_query('login_hint')
196222
expect(redirect_url).not_to have_query('prompt')
197223
expect(redirect_url).not_to have_query('screen_hint')
198224
expect(redirect_url).not_to have_query('organization')

0 commit comments

Comments
 (0)