lib/garage/strategy/auth_server.rb in the_garage-2.6.1 vs lib/garage/strategy/auth_server.rb in the_garage-2.7.0

- old
+ new

@@ -56,14 +56,12 @@ @request = request end def fetch if has_any_valid_credentials? - if has_cacheable_credentials? - fetch_with_cache - else - fetch_without_cache + fetch_access_token&.tap do |access_token| + access_token.token ||= token_string end else nil end rescue Timeout::Error @@ -142,10 +140,18 @@ def bearer_token @bearer_token ||= @request.authorization.try {|o| o.slice(/\ABearer\s+(.+)\z/, 1) } end + def fetch_access_token + if has_cacheable_credentials? + fetch_with_cache + else + fetch_without_cache + end + end + def fetch_with_cache Cache.with_cache("garage_gem/token_cache/#{Garage::VERSION}/#{bearer_token}") do fetch_without_cache end end @@ -159,9 +165,15 @@ nil else raise AuthBackendError.new(response) end end + end + + def token_string + bearer_token.presence || + @request.params[:access_token].presence || + @request.params[:bearer_token].presence end end class Response def initialize(raw)