diff --git a/lib/httpx/plugins/oauth.rb b/lib/httpx/plugins/oauth.rb index a5a16f5d..2722a79d 100644 --- a/lib/httpx/plugins/oauth.rb +++ b/lib/httpx/plugins/oauth.rb @@ -60,16 +60,17 @@ module HTTPX end def load(http) - return unless @token_endpoint && @token_endpoint_auth_method && @grant_type && @scope + return if @token_endpoint && @token_endpoint_auth_method && @grant_type && @scope - metadata = http.get("#{issuer}/.well-known/oauth-authorization-server").raise_for_status.json + metadata = http.get("#{@issuer}/.well-known/oauth-authorization-server").raise_for_status.json - @token_endpoint = metadata["token_endpoint"] - @scope = metadata["scopes_supported"] - @grant_type = Array(metadata["grant_types_supported"]).find { |gr| SUPPORTED_GRANT_TYPES.include?(gr) } - @token_endpoint_auth_method = Array(metadata["token_endpoint_auth_methods_supported"]).find do |am| + @token_endpoint ||= metadata["token_endpoint"] + @scope ||= metadata["scopes_supported"] + @grant_type ||= Array(metadata["grant_types_supported"]).find { |gr| SUPPORTED_GRANT_TYPES.include?(gr) } + @token_endpoint_auth_method ||= Array(metadata["token_endpoint_auth_methods_supported"]).find do |am| SUPPORTED_AUTH_METHODS.include?(am) end + nil end def merge(other)