From 9d0a5a140723e1fc001b3d6c147e37a2403c88d7 Mon Sep 17 00:00:00 2001 From: Stephen Greer Date: Tue, 19 Sep 2023 14:56:38 -0500 Subject: [PATCH 1/2] Display better error message for missing credentials --- lib/omniauth/strategies/base_strategy.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/omniauth/strategies/base_strategy.rb b/lib/omniauth/strategies/base_strategy.rb index 2ca2896..f75af63 100644 --- a/lib/omniauth/strategies/base_strategy.rb +++ b/lib/omniauth/strategies/base_strategy.rb @@ -7,6 +7,7 @@ module OmniAuth module Strategies class BaseStrategy < OmniAuth::Strategies::OpenIDConnect class APIError < StandardError; end + class ClientCredentialsError < StandardError; end def public_key @public_key ||= if options.discovery @@ -18,6 +19,14 @@ def public_key end end + def client + super + rescue AttrRequired::AttrMissing + raise ClientCredentialsError.new( + "#{options[:name].camelize} client credentials not found. Please check your environment." + ) + end + def self.decode_logout_token(token) jwks = fetch_jwks JSON::JWT.decode(token, jwks) From 5b4e9f3aef85818c2e590fe799eeadad162fe770 Mon Sep 17 00:00:00 2001 From: Stephen Greer Date: Tue, 19 Sep 2023 14:59:25 -0500 Subject: [PATCH 2/2] Linting --- lib/omniauth/strategies/base_strategy.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/omniauth/strategies/base_strategy.rb b/lib/omniauth/strategies/base_strategy.rb index f75af63..bd2e4b6 100644 --- a/lib/omniauth/strategies/base_strategy.rb +++ b/lib/omniauth/strategies/base_strategy.rb @@ -22,9 +22,8 @@ def public_key def client super rescue AttrRequired::AttrMissing - raise ClientCredentialsError.new( - "#{options[:name].camelize} client credentials not found. Please check your environment." - ) + raise ClientCredentialsError, + "#{options[:name].camelize} client credentials not found. Please check your environment." end def self.decode_logout_token(token)