omniauth-multipassword 0.1.0

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.
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-multipassword.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,58 @@
1
+ # Omniauth::Multipassword
2
+
3
+ **omniauth-multipassword** is a [OmniAuth](https://github.com/intridea/omniauth)
4
+ strategy that allows to authenticate agains different password strategies at once.
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'omniauth-multipassword'
12
+
13
+ Add multipassword compatible omniauth strategies you want to use:
14
+
15
+ gem 'omniauth-internal'
16
+ gem 'omniauth-kerberos'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install omniauth-multipassword
25
+
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ Rails.application.config.middleware.use OmniAuth::Strategies::MultiPassword, fields: [ :auth_key ] do |mp|
31
+ mp.authenticator :internal
32
+ mp.authenticator :kerberos
33
+ end
34
+ ```
35
+
36
+
37
+ ## Options
38
+
39
+ ** title **
40
+ The title text shown on default login form.
41
+ (default: `"Restricted Access"`)
42
+
43
+ ** fields **
44
+ The request parameter names to fetch username and password.
45
+ (default: `[ "username", "password" ]`)
46
+
47
+
48
+ ### Compatible Strategies
49
+
50
+ * [omniauth-internal](https://github.com/jgraichen/omniauth-internal)
51
+ * [omniauth-kerberos](https://github.com/jgraichen/omniauth-kerberos)
52
+
53
+
54
+ ## License
55
+
56
+ [MIT License](http://www.opensource.org/licenses/mit-license.php)
57
+
58
+ 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,46 @@
1
+ module OmniAuth
2
+ module MultiPassword
3
+ module Base
4
+ def self.included(base)
5
+ base.class_eval do
6
+ option :title, "Restricted Access"
7
+ option :fields, [ :username, :password ]
8
+
9
+ uid { username }
10
+ end
11
+ end
12
+
13
+ def username_id
14
+ options[:fields][0] || "username"
15
+ end
16
+
17
+ def password_id
18
+ options[:fields][1] || "password"
19
+ end
20
+
21
+ def username
22
+ request[username_id]
23
+ end
24
+
25
+ def request=(request)
26
+ @request = request
27
+ end
28
+
29
+ def callback_phase
30
+ if authenticate(username, request[password_id])
31
+ super
32
+ else
33
+ fail!(:invalid_credentials)
34
+ end
35
+ end
36
+
37
+ def request_phase
38
+ OmniAuth::Form.build(:title => options.title, :url => callback_path) do |f|
39
+ f.text_field "Username", username_id
40
+ f.password_field "Password", password_id
41
+ end.to_response
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+ module Omniauth
2
+ module Multipassword
3
+ module VERSION
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ PATCH = 0
7
+ STAGE = nil
8
+
9
+ def self.to_s
10
+ [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join '.'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,77 @@
1
+ require "omniauth"
2
+ require "omniauth/multipassword/base"
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class MultiPassword
7
+ include OmniAuth::Strategy
8
+ include OmniAuth::MultiPassword::Base
9
+
10
+ def initialize(app, *args, &block)
11
+ super(app, *args) do end
12
+
13
+ if block.arity == 0
14
+ instance_eval block
15
+ else
16
+ block.call self
17
+ end
18
+ end
19
+
20
+ def options
21
+ yield @options if block_given?
22
+ @options
23
+ end
24
+
25
+ def authenticator(klass, *args, &block)
26
+ unless klass.is_a?(Class)
27
+ begin
28
+ klass = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}")
29
+ rescue NameError
30
+ raise LoadError, "Could not find matching strategy for #{klass.inspect}." +
31
+ "You may need to install an additional gem (such as omniauth-#{klass})."
32
+ end
33
+ end
34
+
35
+ @authenticators ||= []
36
+ @authenticators << [ klass, args, block ]
37
+ end
38
+
39
+ def callback_phase
40
+ username = request[username_id].to_s
41
+ password = request[password_id].to_s
42
+ if authenticate(username, password)
43
+ super
44
+ else
45
+ return fail!(:invalid_credentials)
46
+ end
47
+ end
48
+
49
+ def authenticate(username, password)
50
+ @authenticators.each do |auth|
51
+ begin
52
+ if auth[2]
53
+ @authenticator = auth[0].new @app, *auth[1], auth[2]
54
+ else
55
+ @authenticator = auth[0].new @app, *auth[1]
56
+ end
57
+ @authenticator.request = self.request
58
+ return true if @authenticator.authenticate(username, password)
59
+ rescue Error => e
60
+ OmniAuth.logger.warn "OmniAuth ERR >>> " + e
61
+ end
62
+ @authenticator = nil
63
+ end
64
+ false
65
+ end
66
+
67
+ info do
68
+ OmniAuth.logger.warn " OmniAuth INFO >> " + @authenticator.info.inspect
69
+ if @authenticator and @authenticator.info.is_a?(Hash)
70
+ @authenticator.info
71
+ else
72
+ {}
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ require "omniauth/multipassword/base"
2
+ require "omniauth/multipassword/version"
3
+ require "omniauth/strategies/multi_password"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth/multipassword/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jan Graichen"]
6
+ gem.email = ["jan.graichen@altimos.de"]
7
+ gem.description = "A OmniAuth strategy to authenticate using different passwort strategies."
8
+ gem.summary = "A OmniAuth strategy to authenticate using different passwort strategies."
9
+ gem.homepage = "https://github.com/jgraichen/omniauth-multipassword"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "omniauth-multipassword"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Omniauth::Multipassword::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-multipassword
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
16
+ requirement: &14982960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *14982960
25
+ description: A OmniAuth strategy to authenticate using different passwort strategies.
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-multipassword.rb
38
+ - lib/omniauth/multipassword/base.rb
39
+ - lib/omniauth/multipassword/version.rb
40
+ - lib/omniauth/strategies/multi_password.rb
41
+ - omniauth-multipassword.gemspec
42
+ homepage: https://github.com/jgraichen/omniauth-multipassword
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.15
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: A OmniAuth strategy to authenticate using different passwort strategies.
66
+ test_files: []