Skip to content

Commit

Permalink
Display better error message for missing credentials (#27)
Browse files Browse the repository at this point in the history
```
irb(main):002:0> OmniAuth::Strategies::NitroId.new({}).client
Traceback (most recent call last):
        5: from bin/console:8:in `<main>'
        4: from (irb):1
        3: from (irb):2:in `rescue in irb_binding'
        2: from /Users/greersa/Workspace/omniauth-nitro-id/lib/omniauth/strategies/base_strategy.rb:22:in `client'
        1: from /Users/greersa/Workspace/omniauth-nitro-id/lib/omniauth/strategies/base_strategy.rb:25:in `rescue in client'
OmniAuth::Strategies::BaseStrategy::ClientCredentialsError (NitroId client credentials not found. Please check your environment.)
```
  • Loading branch information
stephenagreer authored Sep 19, 2023
1 parent 1443fb6 commit be46d05
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/omniauth/strategies/base_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +19,13 @@ def public_key
end
end

def client
super
rescue AttrRequired::AttrMissing
raise ClientCredentialsError,
"#{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)
Expand Down

0 comments on commit be46d05

Please sign in to comment.