omniauth-internal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-internal.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jan Graichen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Omniauth::Internal
2
+
3
+ **omniauth-internal** is a [OmniAuth](https://github.com/intridea/omniauth)
4
+ strategy to authenticate using Rails 3.1 `has_secure_password`
5
+ by delegating to `User.authenticate(username, password)`.
6
+
7
+ **omniauth-internal** can be used as a authenticator for
8
+ [OmniAuth MultiPassword](https://github.com/jgraichen/omniauth-multipassword).
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'omniauth-internal'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install omniauth-internal
23
+
24
+ ## Usage
25
+
26
+ Add a `authenticate` class method to your model:
27
+
28
+ ```ruby
29
+ def self.authenticate(login, password)
30
+ find_by_email(login).try(:authenticate, password)
31
+ end
32
+ ```
33
+
34
+ You can configure the model class used by **omniauth-internal**.
35
+
36
+ ```ruby
37
+ Rails.application.config.middleware.use OmniAuth::Builder do
38
+ provider :internal, :model => ::MyUser
39
+ end
40
+ ```
41
+
42
+ ## Options
43
+
44
+ ** model **
45
+ The model to call `authenticate` on.
46
+ (default: `User`)
47
+
48
+ ** title **
49
+ The title text shown on default login form.
50
+ (default: `"Restricted Access"`)
51
+
52
+ ** fields **
53
+ The request parameter names to fetch username and password.
54
+ (default: `[ "username", "password" ]`)
55
+
56
+
57
+ ## License
58
+
59
+ [MIT License](http://www.opensource.org/licenses/mit-license.php)
60
+
61
+ Copyright (c) 2012, Jan Graichen
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,36 @@
1
+ require "omniauth"
2
+ require "omniauth/multipassword/base"
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Internal
7
+ include OmniAuth::Strategy
8
+ include OmniAuth::MultiPassword::Base
9
+
10
+ info do
11
+ { username: username }
12
+ end
13
+
14
+ def model
15
+ options[:model] || ::User
16
+ end
17
+
18
+ def username
19
+ return @identity.uid if @identity
20
+ super
21
+ end
22
+
23
+ def callback_phase
24
+ if authenticate(username, request[password_id])
25
+ super
26
+ else
27
+ fail!(:invalid_credentials)
28
+ end
29
+ end
30
+
31
+ def authenticate(username, password)
32
+ model.authenticate(username, password)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth/internal/version"
2
+ require "omniauth/strategies/internal"
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Jan Graichen"]
5
+ gem.email = ["jan.graichen@altimos.de"]
6
+ gem.description = "A OmniAuth strategy to authenticate using a model class."
7
+ gem.summary = "A OmniAuth strategy to authenticate using a model class."
8
+ gem.homepage = "https://github.com/jgraichen/omniauth-internal"
9
+
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ gem.name = "omniauth-internal"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = "0.1.0"
16
+
17
+ gem.add_dependency "omniauth-multipassword"
18
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-internal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jan Graichen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-multipassword
16
+ requirement: &15471480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *15471480
25
+ description: A OmniAuth strategy to authenticate using a model class.
26
+ email:
27
+ - jan.graichen@altimos.de
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/omniauth-internal.rb
38
+ - lib/omniauth/strategies/internal.rb
39
+ - omniauth-internal.gemspec
40
+ homepage: https://github.com/jgraichen/omniauth-internal
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.15
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: A OmniAuth strategy to authenticate using a model class.
64
+ test_files: []