Skip to content

Commit 9177468

Browse files
committed
FEATURE: Maintain p parameter between authorization and token request
1 parent 923df4d commit 9177468

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/omniauth_open_id_connect.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class OpenIDConnect < OmniAuth::Strategies::OAuth2
88
option :cache, lambda { |key, &blk| blk.call } # Default no-op cache
99
option :error_handler, lambda { |error, message| nil } # Default no-op handler
1010
option :authorize_options, [:p]
11+
option :token_options, [:p]
1112

1213
option :client_options,
1314
site: 'https://op.com/',
@@ -39,6 +40,10 @@ def authorize_params
3940

4041
params[:scope] = options[:scope]
4142
session['omniauth.nonce'] = params[:nonce] = SecureRandom.hex(32)
43+
44+
options[:token_options].each do |k|
45+
session["omniauth.param.#{k}"] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
46+
end
4247
end
4348
end
4449

@@ -103,10 +108,18 @@ def callback_phase
103108
private
104109

105110
def callback_url
106-
# return "http://localhost:8080/auth/callback/"
107111
full_host + script_name + callback_path
108112
end
109113

114+
def token_params
115+
params = {}
116+
options[:token_options].each do |k|
117+
val = session.delete("omniauth.param.#{k}")
118+
params[k] = val unless [nil, ''].include?(val)
119+
end
120+
super.merge(params)
121+
end
122+
110123
def get_token_options
111124
{ redirect_uri: callback_url,
112125
grant_type: 'authorization_code',

0 commit comments

Comments
 (0)