Skip to content

Commit a74bd6c

Browse files
committed
FIX: Discovery error handling in request phase
1 parent d8f2ceb commit a74bd6c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/omniauth_open_id_connect.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,29 @@ def discover!
2828
client.request(:get, options[:client_options][:discovery_document], parse: :json).parsed
2929
end
3030

31-
{
31+
discovery_params = {
3232
authorize_url: "authorization_endpoint",
3333
token_url: "token_endpoint",
3434
site: "issuer"
35-
}.each do |internal_key, external_key|
35+
}
36+
37+
discovery_params.each do |internal_key, external_key|
3638
val = discovery_document[external_key].to_s
3739
raise ::OmniAuth::OpenIDConnect::DiscoveryError.new("missing discovery parameter #{external_key}") if val.nil? || val.empty?
3840
options[:client_options][internal_key] = val
3941
end
4042

4143
userinfo_endpoint = options[:client_options][:userinfo_endpoint] = discovery_document["userinfo_endpoint"].to_s
42-
if userinfo_endpoint.nil? || userinfo_endpoint.empty?
43-
options.use_userinfo = false
44-
end
44+
options.use_userinfo = false if userinfo_endpoint.nil? || userinfo_endpoint.empty?
4545
end
4646

4747
def request_phase
48-
discover! if options[:discovery]
48+
begin
49+
discover! if options[:discovery]
50+
rescue ::OmniAuth::OpenIDConnect::DiscoveryError => e
51+
fail!(:openid_connect_discovery_error, e)
52+
end
53+
4954
super
5055
end
5156

0 commit comments

Comments
 (0)