Sha256: 261aaa7cba3cfb5e7cd6691042db43c7b8e5def932ae8104a7f9916414dfbc66

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Rails
  # Modular resource-based authentication and authorization for Rails/Rack
  module Auth
    # Rack environment key for all rails-auth credentials
    CREDENTIALS_ENV_KEY = "rails-auth.credentials".freeze

    # Functionality for storing credentials in the Rack environment
    module Credentials
      # Obtain credentials from a Rack environment
      #
      # @param [Hash] :env Rack environment
      #
      def credentials(env)
        env.fetch(CREDENTIALS_ENV_KEY, {})
      end

      # Add a credential to the Rack environment
      #
      # @param [Hash] :env Rack environment
      # @param [String] :type credential type to add to the environment
      # @param [Object] :credential object to add to the environment
      #
      def add_credential(env, type, credential)
        credentials = env[CREDENTIALS_ENV_KEY] ||= {}

        raise ArgumentError, "credential #{type} already added to request" if credentials.key?(type)
        credentials[type] = credential

        env
      end
    end

    # Include these functions in Rails::Auth for convenience
    extend Credentials
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rails-auth-1.0.0 lib/rails/auth/credentials.rb
rails-auth-0.5.3 lib/rails/auth/credentials.rb
rails-auth-0.5.2 lib/rails/auth/credentials.rb
rails-auth-0.5.1 lib/rails/auth/credentials.rb
rails-auth-0.5.0 lib/rails/auth/credentials.rb
rails-auth-0.4.1 lib/rails/auth/credentials.rb
rails-auth-0.4.0 lib/rails/auth/credentials.rb
rails-auth-0.3.0 lib/rails/auth/credentials.rb