omniauth-multipassword 0.3.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4c42cc59feffb560101a1ca960ea75b5099054097dc688570f814fde8a07d33a
4
+ data.tar.gz: d8a94787d62f2d9ab2a8435cbaa81d087a4a2332e703a560fa907e3da0c9f9d5
5
+ SHA512:
6
+ metadata.gz: caef3ce2da16ace112cb73c2f178fb3909ad5fe184f57912cc0ae50622511e6f581638c0f4ab79d84c39229486b2114cc4799d47ba1057e02129392f892e4173
7
+ data.tar.gz: 2bb20ced2304ba9496012e1b186619b7149fc4c19265b013305afb1ce68a3c76b12fa1d7300432f38851fe6d7e1c7fa21225f337b227da89662b47ace17d9937
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ [*]
7
+ indent_style = space
8
+ indent_size = 2
9
+ end_of_line = lf
10
+ charset = utf-8
11
+ trim_trailing_whitespace = true
12
+ insert_final_newline = true
@@ -0,0 +1,46 @@
1
+ ---
2
+ name: test
3
+ on: push
4
+ jobs:
5
+ rspec:
6
+ name: "Ruby ${{ matrix.ruby }}"
7
+ runs-on: ubuntu-20.04
8
+
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby:
13
+ - "3.0"
14
+ - "2.7"
15
+ - "2.6"
16
+ - "2.5"
17
+
18
+ steps:
19
+ - uses: actions/checkout@master
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ bundler-cache: True
24
+ env:
25
+ BUNDLE_WITHOUT: development
26
+ BUNDLE_JOBS: 4
27
+ BUNDLE_RETRY: 3
28
+
29
+ - run: bundle exec rspec --color
30
+
31
+ rubocop:
32
+ name: rubocop
33
+ runs-on: ubuntu-20.04
34
+
35
+ steps:
36
+ - uses: actions/checkout@master
37
+ - uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: 3.0
40
+ bundler-cache: True
41
+ env:
42
+ BUNDLE_WITHOUT: development
43
+ BUNDLE_JOBS: 4
44
+ BUNDLE_RETRY: 3
45
+
46
+ - run: bundle exec rubocop --parallel --fail-level E
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --backtrace
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ inherit_gem:
2
+ my-rubocop: default.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
6
+ SuggestExtensions: False
7
+
8
+ Naming/FileName:
9
+ Exclude:
10
+ - lib/omniauth-multipassword.rb
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - '2.4.0'
6
+ - '2.3.3'
7
+ - '2.2.6'
8
+ - '2.1.10'
9
+ after_success:
10
+ - bundle exec codeclimate-test-reporter
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # CHANGELOG
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Changelog](http://keepachangelog.com/).
5
+
6
+ ## Unreleased
7
+ ---
8
+
9
+ ### New
10
+
11
+ ### Changes
12
+
13
+ ### Fixes
14
+
15
+ ### Breaks
16
+ * Updated strategy to OmniAuth >= 2.0
17
+
18
+
data/Gemfile CHANGED
@@ -1,4 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in omniauth-multipassword.gemspec
4
6
  gemspec
7
+
8
+ gem 'rake'
9
+ gem 'rake-release'
10
+
11
+ group :test do
12
+ gem 'rack-test'
13
+
14
+ gem 'rspec', '~> 3.0'
15
+
16
+ gem 'codecov', require: false
17
+ gem 'simplecov', require: false
18
+
19
+ gem 'my-rubocop', github: 'jgraichen/my-rubocop', ref: 'v2'
20
+ end
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # Omniauth::Multipassword
2
2
 
3
+ [![Build Status](https://travis-ci.org/jgraichen/omniauth-multipassword.svg?branch=master)](https://travis-ci.org/jgraichen/omniauth-multipassword)
4
+ [![Code Climate](https://codeclimate.com/github/jgraichen/omniauth-multipassword/badges/gpa.svg)](https://codeclimate.com/github/jgraichen/omniauth-multipassword)
5
+ [![Test Coverage](https://codeclimate.com/github/jgraichen/omniauth-multipassword/badges/coverage.svg)](https://codeclimate.com/github/jgraichen/omniauth-multipassword/coverage)
6
+
3
7
  **omniauth-multipassword** is a [OmniAuth](https://github.com/intridea/omniauth)
4
- strategy that allows to authenticate agains different password strategies at once.
8
+ strategy that allows to authenticate again different password strategies at once.
5
9
 
6
10
 
7
11
  ## Installation
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake/release'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OmniAuth
2
4
  module MultiPassword
3
5
  module Base
4
6
  def self.included(base)
5
7
  base.class_eval do
6
- option :title, "Restricted Access"
7
- option :fields, [ :username, :password ]
8
+ option :title, 'Restricted Access'
9
+ option :fields, %i[username password]
8
10
 
9
- uid { username }
11
+ uid { username }
10
12
  end
11
13
  end
12
14
 
13
15
  def username_id
14
- options[:fields][0] || "username"
16
+ options[:fields][0] || 'username'
15
17
  end
16
18
 
17
19
  def password_id
18
- options[:fields][1] || "password"
20
+ options[:fields][1] || 'password'
19
21
  end
20
22
 
21
23
  def username
@@ -37,12 +39,18 @@ module OmniAuth
37
39
  end
38
40
 
39
41
  def request_phase
40
- OmniAuth::Form.build(:title => options.title, :url => callback_path) do |f|
41
- f.text_field "Username", username_id
42
- f.password_field "Password", password_id
42
+ OmniAuth::Form.build(title: options.title, url: callback_url) do |f|
43
+ f.text_field 'Username', username_id
44
+ f.password_field 'Password', password_id
43
45
  end.to_response
44
46
  end
45
47
 
48
+ def other_phase
49
+ # OmniAuth, by default, disables "GET" requests for security reasons.
50
+ # This effectively disables showing a password form on a GET request to
51
+ # the `request_phase`. Instead, we hook the GET requests here.
52
+ return request_phase if on_request_path?
53
+ end
46
54
  end
47
55
  end
48
56
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Omniauth
2
4
  module Multipassword
3
5
  module VERSION
4
- MAJOR = 0
5
- MINOR = 3
6
+ MAJOR = 2
7
+ MINOR = 0
6
8
  PATCH = 0
7
- STAGE = nil
9
+ STAGE = 'rc1'
8
10
 
9
11
  def self.to_s
10
12
  [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join '.'
@@ -1,5 +1,7 @@
1
- require "omniauth"
2
- require "omniauth/multipassword/base"
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth'
4
+ require 'omniauth/multipassword/base'
3
5
 
4
6
  module OmniAuth
5
7
  module Strategies
@@ -8,12 +10,16 @@ module OmniAuth
8
10
  include OmniAuth::MultiPassword::Base
9
11
 
10
12
  def initialize(app, *args, &block)
11
- super(app, *args) do end
13
+ super(app, *args) do
14
+ # Do pass an empty block, as otherwise the captured block would be
15
+ # passed to `super`, but this needs to be evaluate inside this
16
+ # middleware, not omniauth's Rack builder instance.
17
+ end
12
18
 
13
- if block.arity == 0
14
- instance_eval block
19
+ if block.arity.zero?
20
+ instance_eval(&block)
15
21
  else
16
- block.call self
22
+ yield self
17
23
  end
18
24
  end
19
25
 
@@ -25,16 +31,16 @@ module OmniAuth
25
31
  def authenticator(klass, *args, &block)
26
32
  unless klass.is_a?(Class)
27
33
  begin
28
- klass = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}")
34
+ klass = OmniAuth::Strategies.const_get(OmniAuth::Utils.camelize(klass.to_s).to_s)
29
35
  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})."
36
+ raise LoadError.new("Could not find matching strategy for #{klass.inspect}." \
37
+ "You may need to install an additional gem (such as omniauth-#{klass}).")
32
38
  end
33
39
  end
34
40
 
35
41
  args << block if block
36
42
  @authenticators ||= []
37
- @authenticators << [ klass, args ]
43
+ @authenticators << [klass, args]
38
44
  end
39
45
 
40
46
  def callback_phase
@@ -43,7 +49,7 @@ module OmniAuth
43
49
  if authenticate(username, password)
44
50
  super
45
51
  else
46
- return fail!(:invalid_credentials)
52
+ fail!(:invalid_credentials)
47
53
  end
48
54
  end
49
55
 
@@ -52,11 +58,9 @@ module OmniAuth
52
58
  begin
53
59
  @authenticator = auth[0].new @app, *auth[1]
54
60
  @authenticator.init_authenticator(@request, @env, username)
55
- if @authenticator.authenticate(username, password)
56
- return true
57
- end
61
+ return true if @authenticator.authenticate(username, password)
58
62
  rescue Error => e
59
- OmniAuth.logger.warn "OmniAuth ERR >>> " + e
63
+ OmniAuth.logger.warn "OmniAuth ERR >>> #{e}"
60
64
  end
61
65
  @authenticator = nil
62
66
  end
@@ -65,6 +69,7 @@ module OmniAuth
65
69
 
66
70
  def name
67
71
  return @authenticator.name if @authenticator
72
+
68
73
  super
69
74
  end
70
75
 
@@ -1,3 +1,5 @@
1
- require "omniauth/multipassword/base"
2
- require "omniauth/multipassword/version"
3
- require "omniauth/strategies/multi_password"
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/multipassword/base'
4
+ require 'omniauth/multipassword/version'
5
+ require 'omniauth/strategies/multi_password'
@@ -1,19 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/omniauth/multipassword/version', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/omniauth/multipassword/version', __dir__)
3
4
 
4
5
  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"
6
+ gem.authors = ['Jan Graichen']
7
+ gem.email = ['jgraichen@altimos.de']
8
+ gem.description = 'A OmniAuth strategy to authenticate using different passwort strategies.'
9
+ gem.summary = 'A OmniAuth strategy to authenticate using different passwort strategies.'
10
+ gem.homepage = 'https://github.com/jgraichen/omniauth-multipassword'
11
+ gem.license = 'MIT'
12
+
13
+ gem.required_ruby_version = '>= 2.5'
14
+ gem.metadata = {
15
+ 'rubygems_mfa_required' => 'true',
16
+ }
10
17
 
11
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
12
19
  gem.files = `git ls-files`.split("\n")
13
20
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
- gem.name = "omniauth-multipassword"
15
- gem.require_paths = ["lib"]
21
+ gem.name = 'omniauth-multipassword'
22
+ gem.require_paths = ['lib']
16
23
  gem.version = Omniauth::Multipassword::VERSION
17
24
 
18
- gem.add_dependency 'omniauth', '~> 1.0'
25
+ gem.add_dependency 'omniauth', '~> 2.0'
19
26
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'rack/test'
5
+
6
+ describe OmniAuth::MultiPassword::Base do # rubocop:disable RSpec/FilePath
7
+ subject { strategy }
8
+
9
+ let(:app) { instance_double(Proc) }
10
+ let(:strategy) do
11
+ OmniAuth::Strategies::OneTest.new(app, *args, &block)
12
+ end
13
+ let(:args) { [] }
14
+ let(:block) { nil }
15
+
16
+ describe '#username_id' do
17
+ subject(:username_id) { strategy.username_id }
18
+
19
+ it 'defaults to :username' do
20
+ expect(username_id).to eq :username
21
+ end
22
+
23
+ context 'when configured' do
24
+ let(:args) { [{fields: %i[user pass]}] }
25
+
26
+ it { is_expected.to eq :user }
27
+ end
28
+ end
29
+
30
+ describe '#password_id' do
31
+ subject(:password_id) { strategy.password_id }
32
+
33
+ it 'defaults to :password' do
34
+ expect(password_id).to eq :password
35
+ end
36
+
37
+ context 'when configured' do
38
+ let(:args) { [{fields: %i[user pass]}] }
39
+
40
+ it { is_expected.to eq :pass }
41
+ end
42
+ end
43
+
44
+ describe 'single strategy' do
45
+ include Rack::Test::Methods
46
+
47
+ let(:app) do
48
+ Rack::Builder.new do
49
+ use OmniAuth::Test::PhonySession
50
+ use OmniAuth::Strategies::OneTest
51
+ run ->(env) { [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
52
+ end.to_app
53
+ end
54
+
55
+ it 'shows login FORM' do
56
+ get '/auth/onetest'
57
+
58
+ expect(last_response.body).to include '<form'
59
+ end
60
+
61
+ it 'redirect on wrong password' do
62
+ post '/auth/onetest/callback', username: 'john', password: 'wrong'
63
+ expect(last_response).to be_redirect
64
+ expect(last_response.headers['Location']).to eq '/auth/failure?message=invalid_credentials&strategy=onetest'
65
+ end
66
+
67
+ it 'authenticates john with correct password' do
68
+ post '/auth/onetest/callback', username: 'john', password: 'secret'
69
+ expect(last_response.body).to eq 'true'
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'rack/test'
5
+
6
+ describe OmniAuth::Strategies::MultiPassword do # rubocop:disable RSpec/FilePath
7
+ include Rack::Test::Methods
8
+
9
+ let(:app) do
10
+ Rack::Builder.new do
11
+ use OmniAuth::Test::PhonySession
12
+ use OmniAuth::Strategies::MultiPassword do
13
+ authenticator :one_test
14
+ authenticator :two_test
15
+ end
16
+ run ->(env) { [404, {'Content-Type' => 'text/plain'}, [env['omniauth.auth']['uid'].to_s]] }
17
+ end.to_app
18
+ end
19
+
20
+ it 'shows login FORM' do
21
+ get '/auth/multipassword'
22
+
23
+ expect(last_response.body).to include '<form'
24
+ end
25
+
26
+ it 'redirect on all failed strategies' do
27
+ post '/auth/multipassword/callback', username: 'paul', password: 'wrong'
28
+
29
+ expect(last_response).to be_redirect
30
+ expect(last_response.headers['Location']).to eq '/auth/failure?message=invalid_credentials&strategy=multipassword'
31
+ end
32
+
33
+ it 'authenticates john' do
34
+ post '/auth/multipassword/callback', username: 'john', password: 'secret'
35
+
36
+ expect(last_response.body).to eq 'john'
37
+ end
38
+
39
+ it 'authenticates jane' do
40
+ post '/auth/multipassword/callback', username: 'jane', password: '1234'
41
+
42
+ expect(last_response.body).to eq 'jane'
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+ require 'simplecov'
5
+
6
+ if ENV['CI']
7
+ require 'codecov'
8
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
9
+ end
10
+
11
+ SimpleCov.start do
12
+ add_filter 'spec'
13
+ end
14
+
15
+ require 'omniauth-multipassword'
16
+
17
+ Dir[File.expand_path('spec/support/**/*.rb')].sort.each {|f| require f }
18
+
19
+ RSpec.configure do |config|
20
+ config.order = 'random'
21
+
22
+ config.before do
23
+ OmniAuth.config.logger = Logger.new(IO::NULL)
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class OneTest
6
+ include OmniAuth::Strategy
7
+ include OmniAuth::MultiPassword::Base
8
+
9
+ def authenticate(username, password)
10
+ username == 'john' && password == 'secret'
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ module OmniAuth
17
+ module Strategies
18
+ class TwoTest
19
+ include OmniAuth::Strategy
20
+ include OmniAuth::MultiPassword::Base
21
+
22
+ def authenticate(username, password)
23
+ username == 'jane' && password == '1234'
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,35 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-multipassword
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 2.0.0.rc1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jan Graichen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-21 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: omniauth
16
- requirement: &11704160 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '1.0'
19
+ version: '2.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *11704160
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
25
27
  description: A OmniAuth strategy to authenticate using different passwort strategies.
26
28
  email:
27
- - jan.graichen@altimos.de
29
+ - jgraichen@altimos.de
28
30
  executables: []
29
31
  extensions: []
30
32
  extra_rdoc_files: []
31
33
  files:
32
- - .gitignore
34
+ - ".editorconfig"
35
+ - ".github/workflows/test.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - ".rubocop.yml"
39
+ - ".travis.yml"
40
+ - CHANGELOG.md
33
41
  - Gemfile
34
42
  - LICENSE
35
43
  - README.md
@@ -39,28 +47,32 @@ files:
39
47
  - lib/omniauth/multipassword/version.rb
40
48
  - lib/omniauth/strategies/multi_password.rb
41
49
  - omniauth-multipassword.gemspec
50
+ - spec/omniauth/multipassword/base_spec.rb
51
+ - spec/omniauth/strategy/multi_password_spec.rb
52
+ - spec/spec_helper.rb
53
+ - spec/support/strategies.rb
42
54
  homepage: https://github.com/jgraichen/omniauth-multipassword
43
- licenses: []
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ rubygems_mfa_required: 'true'
44
59
  post_install_message:
45
60
  rdoc_options: []
46
61
  require_paths:
47
62
  - lib
48
63
  required_ruby_version: !ruby/object:Gem::Requirement
49
- none: false
50
64
  requirements:
51
- - - ! '>='
65
+ - - ">="
52
66
  - !ruby/object:Gem::Version
53
- version: '0'
67
+ version: '2.5'
54
68
  required_rubygems_version: !ruby/object:Gem::Requirement
55
- none: false
56
69
  requirements:
57
- - - ! '>='
70
+ - - ">"
58
71
  - !ruby/object:Gem::Version
59
- version: '0'
72
+ version: 1.3.1
60
73
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 1.8.15
74
+ rubygems_version: 3.2.22
63
75
  signing_key:
64
- specification_version: 3
76
+ specification_version: 4
65
77
  summary: A OmniAuth strategy to authenticate using different passwort strategies.
66
78
  test_files: []