Sha256: 548c250cfa9103ead701f3e4d97a39b50e295649bc3c37d27dd49381689a7be6

Contents?: true

Size: 1.66 KB

Versions: 15

Compression:

Stored size: 1.66 KB

Contents

module OmniAuth
  module Strategies
    # The Developer strategy is a very simple strategy that can be used as a
    # placeholder in your application until a different authentication strategy
    # is swapped in. It has zero security and should *never* be used in a
    # production setting.
    #
    # ## Usage
    #
    # To use the Developer strategy, all you need to do is put it in like any
    # other strategy:
    #
    # @example Basic Usage
    #
    #   use OmniAuth::Builder do
    #     provider :developer
    #   end
    #
    # @example Custom Fields
    #
    #   use OmniAuth::Builder do
    #     provider :developer,
    #       :fields => [:first_name, :last_name],
    #       :uid_field => :last_name
    #   end
    #
    # This will create a strategy that, when the user visits `/auth/developer`
    # they will be presented a form that prompts for (by default) their name
    # and email address. The auth hash will be populated with these fields and
    # the `uid` will simply be set to the provided email.
    class Developer
      include OmniAuth::Strategy

      option :fields, [:name, :email]
      option :uid_field, :email

      def request_phase
        form = OmniAuth::Form.new(:title => 'User Info', :url => callback_path)
        options.fields.each do |field|
          form.text_field field.to_s.capitalize.tr('_', ' '), field.to_s
        end
        form.button 'Sign In'
        form.to_response
      end

      uid do
        request.params[options.uid_field.to_s]
      end

      info do
        options.fields.inject({}) do |hash, field|
          hash[field] = request.params[field.to_s]
          hash
        end
      end
    end
  end
end

Version data entries

15 entries across 13 versions & 2 rubygems

Version Path
omniauth-1.4.3 lib/omniauth/strategies/developer.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/omniauth-1.6.1/lib/omniauth/strategies/developer.rb
tdiary-5.0.5 vendor/bundle/gems/omniauth-1.6.1/lib/omniauth/strategies/developer.rb
tdiary-5.0.4 vendor/bundle/gems/omniauth-1.6.1/lib/omniauth/strategies/developer.rb
omniauth-1.6.1 lib/omniauth/strategies/developer.rb
omniauth-1.6.0 lib/omniauth/strategies/developer.rb
omniauth-1.5.0 lib/omniauth/strategies/developer.rb
omniauth-1.4.2 lib/omniauth/strategies/developer.rb
omniauth-1.4.1 lib/omniauth/strategies/developer.rb
omniauth-1.4.0 lib/omniauth/strategies/developer.rb
omniauth-1.3.2 lib/omniauth/strategies/developer.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/omniauth-1.3.1/lib/omniauth/strategies/developer.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/omniauth-1.3.1/lib/omniauth/strategies/developer.rb
omniauth-1.3.1 lib/omniauth/strategies/developer.rb
omniauth-1.3.0 lib/omniauth/strategies/developer.rb