Sha256: 039b0d00e24a94ce0da564a0320ac5bdfe29e467ab23a672504cf636ddf87e59

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

module WineBouncer
  module AuthStrategies
    class Protected < WineBouncer::BaseStrategy

      def endpoint_protected?
        has_authorizations?
      end

      def has_auth_scopes?
        endpoint_authorizations &&
          endpoint_authorizations.has_key?(:scopes) &&
          endpoint_authorizations[:scopes].any?
      end

      def auth_scopes
        endpoint_authorizations[:scopes].map(&:to_sym)
      end

      private

      def nil_authorizations?
        endpoint_authorizations.nil?
      end


      # returns true if an authorization hash has been found
      # First it checks for the old syntax, then for the new.
      def has_authorizations?
        (nil_authorizations? || !!endpoint_authorizations) && scope_keys?
      end

      # if false or nil scopes are entered the authorization should be skipped.
      # nil_authorizations? is used to check against the legacy hash.
      def scope_keys?
        nil_authorizations? || endpoint_authorizations[:scopes] != [false]
      end

      def endpoint_authorizations
        api_context.options[:route_options][:auth]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wine_bouncer-0.5.0 lib/wine_bouncer/auth_strategies/protected.rb
wine_bouncer-0.4.0 lib/wine_bouncer/auth_strategies/protected.rb
wine_bouncer-0.3.1 lib/wine_bouncer/auth_strategies/protected.rb