devise_custom_authenticatable 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +4 -0
- data/README.md +61 -3
- data/devise_custom_authenticatable.gemspec +2 -3
- data/lib/devise_custom_authenticatable/version.rb +1 -1
- metadata +23 -40
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 12bd7f8777135a62852d2ba22efd0f7cec1a16e6
         | 
| 4 | 
            +
              data.tar.gz: 26405720e35ba421a11e456f164096eeb2567527
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 87ced17afe13cdf57cce3938a046045651f06ff7498fa9a0341d2e284fdae4b54b08f5be835db149ad07209ecd87f0baeb8a6dffb32aeb5e2452bcaa470b0a21
         | 
| 7 | 
            +
              data.tar.gz: 6bb9e8176658e0aa3d5551071555077c734547b7b4bc606fad84f5c82cad7c7e6b64a432eb9e61554e6a35be7333e636b5057ea6eb19f59a083f3172ae282528
         | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,8 +1,9 @@ | |
| 1 1 | 
             
            # DeviseCustomAuthenticatable
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 3 | 
            +
            [](https://travis-ci.org/AMekss/devise_custom_authenticatable)
         | 
| 4 | 
            +
            [](http://badge.fury.io/rb/devise_custom_authenticatable)
         | 
| 4 5 |  | 
| 5 | 
            -
             | 
| 6 | 
            +
            This gem is extension for [Devise](http://github.com/plataformatec/devise) authentication. It provides custom strategy via extended module `:custom_authenticatable` which is simple way how to customize Devise authentication logic but stay inline with all other features e.g. modules `:rememberable`, `:lockable`, `:timeoutable`, default controllers and even views if you like. `:custom_authenticatable` can work together with Devise default authentication strategy `:database_authenticatable` or on its own.
         | 
| 6 7 |  | 
| 7 8 | 
             
            ## Installation
         | 
| 8 9 |  | 
| @@ -18,9 +19,66 @@ Or install it yourself as: | |
| 18 19 |  | 
| 19 20 | 
             
                $ gem install devise_custom_authenticatable
         | 
| 20 21 |  | 
| 22 | 
            +
            ##Prerequisites
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            * devise >= 2.0
         | 
| 25 | 
            +
             | 
| 21 26 | 
             
            ## Usage
         | 
| 22 27 |  | 
| 23 | 
            -
             | 
| 28 | 
            +
            [Devise](http://github.com/plataformatec/devise) should be already installed and enabled for any resource in your app. Open Devise enabled model and add `:custom_authenticatable`. When strategy is enabled it'll try to call `#valid_for_custom_authentication?` method on resource model with password. Define this method and return true in order to authenticate user. If there is no such method for model or it returns false/nil then authentication handling will be passed to next strategy e.g. `:database_authenticatable`, if there is no other strategies left for resource then authentication will be failed. For example:
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ```ruby
         | 
| 31 | 
            +
                devise :custom_authenticatable, :database_authenticatable, :trackable, :lockable, :timeoutable
         | 
| 32 | 
            +
                # OR
         | 
| 33 | 
            +
                devise :custom_authenticatable, :trackable, :lockable, :timeoutable
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                # AND
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def valid_for_custom_authentication?(password)
         | 
| 38 | 
            +
                  # Your authentication logic goes here and returns either true or false
         | 
| 39 | 
            +
                  LDAP.authenticate(self.username, password)
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
            ```
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            This gem also provide handy helper `#authenticated_by_any_custom_strategy?` for managing your custom authentication methods. For example you would like to provide LDAP authentication for users, but also would like to have some dummy password in development environments. You can write something like this:
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            ```ruby
         | 
| 46 | 
            +
                class User
         | 
| 47 | 
            +
                  devise :custom_authenticatable, :trackable, :lockable, :timeoutable
         | 
| 48 | 
            +
                  # ...
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  def valid_for_custom_authentication?(password)
         | 
| 51 | 
            +
                    authenticated_by_any_custom_strategy?(password, :development, :ldap)
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def authenticated_by_development_strategy?(password)
         | 
| 55 | 
            +
                    if %w{development test demo}.include?(Rails.env)
         | 
| 56 | 
            +
                      password == 'dummy'
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  def authenticated_by_ldap_strategy?(password)
         | 
| 61 | 
            +
                    logger.info "  Authenticate user '#{self.user_name}' with Active Directory..."
         | 
| 62 | 
            +
                    !!Ldap.authenticate(self.username, password)
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
            ```
         | 
| 66 | 
            +
             | 
| 67 | 
            +
            It will call all `authenticated_by_<strategy_name>_strategy?(password)` in turn if any of strategy methods return true authentication succeed otherwise fail.
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            **Note!** If you are using development strategies in your app always cover it with unit tests so it never get used in production by mistake, something like this for rspec:
         | 
| 70 | 
            +
             | 
| 71 | 
            +
            ```ruby
         | 
| 72 | 
            +
                it "development strategy shouldn't be enabled for Production environment" do
         | 
| 73 | 
            +
                  Rails.stub(env: ActiveSupport::StringInquirer.new("production"))
         | 
| 74 | 
            +
                  expect(@user.authenticated_by_development_strategy?('dummy')).not_to be_true
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
            ```
         | 
| 77 | 
            +
             | 
| 78 | 
            +
             | 
| 79 | 
            +
            ## TODO
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            * Write Integration tests
         | 
| 24 82 |  | 
| 25 83 | 
             
            ## Contributing
         | 
| 26 84 |  | 
| @@ -19,9 +19,8 @@ Gem::Specification.new do |spec| | |
| 19 19 | 
             
              spec.require_paths = ["lib"]
         | 
| 20 20 |  | 
| 21 21 | 
             
              spec.add_development_dependency "bundler", "~> 1.3"
         | 
| 22 | 
            -
              spec.add_development_dependency " | 
| 23 | 
            -
              spec.add_development_dependency "rspec"
         | 
| 22 | 
            +
              spec.add_development_dependency "rspec", "~> 2.0"
         | 
| 24 23 |  | 
| 25 | 
            -
              spec.add_dependency "devise", " | 
| 24 | 
            +
              spec.add_dependency "devise", ">= 2", "< 4"
         | 
| 26 25 |  | 
| 27 26 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,20 +1,18 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: devise_custom_authenticatable
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 0.1.1
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - Artūrs Mekšs
         | 
| 9 8 | 
             
            autorequire: 
         | 
| 10 9 | 
             
            bindir: bin
         | 
| 11 10 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-02-09 00:00:00.000000000 Z
         | 
| 13 12 | 
             
            dependencies:
         | 
| 14 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 14 | 
             
              name: bundler
         | 
| 16 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            -
                none: false
         | 
| 18 16 | 
             
                requirements:
         | 
| 19 17 | 
             
                - - ~>
         | 
| 20 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -22,59 +20,44 @@ dependencies: | |
| 22 20 | 
             
              type: :development
         | 
| 23 21 | 
             
              prerelease: false
         | 
| 24 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            -
                none: false
         | 
| 26 23 | 
             
                requirements:
         | 
| 27 24 | 
             
                - - ~>
         | 
| 28 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 29 26 | 
             
                    version: '1.3'
         | 
| 30 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 31 | 
            -
              name: rake
         | 
| 32 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            -
                none: false
         | 
| 34 | 
            -
                requirements:
         | 
| 35 | 
            -
                - - ! '>='
         | 
| 36 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 37 | 
            -
                    version: '0'
         | 
| 38 | 
            -
              type: :development
         | 
| 39 | 
            -
              prerelease: false
         | 
| 40 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            -
                none: false
         | 
| 42 | 
            -
                requirements:
         | 
| 43 | 
            -
                - - ! '>='
         | 
| 44 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 45 | 
            -
                    version: '0'
         | 
| 46 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 47 28 | 
             
              name: rspec
         | 
| 48 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 | 
            -
                none: false
         | 
| 50 30 | 
             
                requirements:
         | 
| 51 | 
            -
                - -  | 
| 31 | 
            +
                - - ~>
         | 
| 52 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            -
                    version: '0'
         | 
| 33 | 
            +
                    version: '2.0'
         | 
| 54 34 | 
             
              type: :development
         | 
| 55 35 | 
             
              prerelease: false
         | 
| 56 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            -
                none: false
         | 
| 58 37 | 
             
                requirements:
         | 
| 59 | 
            -
                - -  | 
| 38 | 
            +
                - - ~>
         | 
| 60 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            -
                    version: '0'
         | 
| 40 | 
            +
                    version: '2.0'
         | 
| 62 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 63 42 | 
             
              name: devise
         | 
| 64 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 65 | 
            -
                none: false
         | 
| 66 44 | 
             
                requirements:
         | 
| 67 | 
            -
                - -  | 
| 45 | 
            +
                - - '>='
         | 
| 68 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            -
                    version: ' | 
| 47 | 
            +
                    version: '2'
         | 
| 48 | 
            +
                - - <
         | 
| 49 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 50 | 
            +
                    version: '4'
         | 
| 70 51 | 
             
              type: :runtime
         | 
| 71 52 | 
             
              prerelease: false
         | 
| 72 53 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 73 | 
            -
                none: false
         | 
| 74 54 | 
             
                requirements:
         | 
| 75 | 
            -
                - -  | 
| 55 | 
            +
                - - '>='
         | 
| 56 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 57 | 
            +
                    version: '2'
         | 
| 58 | 
            +
                - - <
         | 
| 76 59 | 
             
                  - !ruby/object:Gem::Version
         | 
| 77 | 
            -
                    version: ' | 
| 60 | 
            +
                    version: '4'
         | 
| 78 61 | 
             
            description: Simple way to customize devise authentication logic and still be inline
         | 
| 79 62 | 
             
              with all other devise parts
         | 
| 80 63 | 
             
            email:
         | 
| @@ -85,6 +68,7 @@ extra_rdoc_files: [] | |
| 85 68 | 
             
            files:
         | 
| 86 69 | 
             
            - .gitignore
         | 
| 87 70 | 
             
            - .rspec
         | 
| 71 | 
            +
            - .travis.yml
         | 
| 88 72 | 
             
            - CHANGELOG.md
         | 
| 89 73 | 
             
            - Gemfile
         | 
| 90 74 | 
             
            - LICENSE.txt
         | 
| @@ -100,28 +84,27 @@ files: | |
| 100 84 | 
             
            homepage: https://github.com/AMekss/devise_custom_authenticatable
         | 
| 101 85 | 
             
            licenses:
         | 
| 102 86 | 
             
            - MIT
         | 
| 87 | 
            +
            metadata: {}
         | 
| 103 88 | 
             
            post_install_message: 
         | 
| 104 89 | 
             
            rdoc_options: []
         | 
| 105 90 | 
             
            require_paths:
         | 
| 106 91 | 
             
            - lib
         | 
| 107 92 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 108 | 
            -
              none: false
         | 
| 109 93 | 
             
              requirements:
         | 
| 110 | 
            -
              - -  | 
| 94 | 
            +
              - - '>='
         | 
| 111 95 | 
             
                - !ruby/object:Gem::Version
         | 
| 112 96 | 
             
                  version: '0'
         | 
| 113 97 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 114 | 
            -
              none: false
         | 
| 115 98 | 
             
              requirements:
         | 
| 116 | 
            -
              - -  | 
| 99 | 
            +
              - - '>='
         | 
| 117 100 | 
             
                - !ruby/object:Gem::Version
         | 
| 118 101 | 
             
                  version: '0'
         | 
| 119 102 | 
             
            requirements: []
         | 
| 120 103 | 
             
            rubyforge_project: 
         | 
| 121 | 
            -
            rubygems_version:  | 
| 104 | 
            +
            rubygems_version: 2.2.1
         | 
| 122 105 | 
             
            signing_key: 
         | 
| 123 | 
            -
            specification_version:  | 
| 124 | 
            -
            summary:  | 
| 106 | 
            +
            specification_version: 4
         | 
| 107 | 
            +
            summary: 'Extends Devise with new module :custom_authenticatable, when enabled it
         | 
| 125 108 | 
             
              will call #valid_for_custom_authentication? method on resource model for your customizations'
         | 
| 126 109 | 
             
            test_files:
         | 
| 127 110 | 
             
            - spec/devise/models/custom_authenticatable_spec.rb
         |