devise_userbin 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62ac1a97256c536aaa27b38da2680adae4188069
4
- data.tar.gz: 51ce5f3fd7d56c546766c80eaae989e8e25e34d5
3
+ metadata.gz: 71f002bedf94193a3be8c19a48c92c1e31288c5e
4
+ data.tar.gz: cd8ee013cb8ff1c4915b29bc7fcf4761db799aff
5
5
  SHA512:
6
- metadata.gz: cd3bcfef54d982643b0b166f3c685f232568cb744aa5d3cd6c30b5d5ae19158ecfdb7fc214fae588e467c7c6ad9005c53090b544dc983c715bb1c97fb61b3cdc
7
- data.tar.gz: b06acd12730d908a1103d4806b4a92f3783738105a4f4def5c1b82f8a2a2ff94bb5e41a5e8a9734625d5f79641f8518bd3e62bb5c7b151834e06557b56c1aefa
6
+ metadata.gz: 58e57d7da0e13a6d88e06f007f73e26e8deefc865e24a4ec2baf2777ab3949e0a16719790b23bf043833bb1d884d879246483a888433dfbe37db82ecb405704b
7
+ data.tar.gz: f0b4b273c918a6c5812dc0da9c9d8313dac3b06be65261f6bbee05a3a867aae9f8a6c1b6ec88b02e72702cab36687ca80f8b1726a0152bb5c151642364e403cc
@@ -10,8 +10,9 @@ class Devise::DeviseUserbinController < DeviseController
10
10
 
11
11
  Devise.mappings.keys.flatten.any? do |scope|
12
12
  begin
13
- session["#{scope}_userbin"] =
14
- Userbin.verify_code(session["#{scope}_userbin"], params[:code])
13
+ send("current_#{scope_name}") # initialize after_set_user in warden
14
+ env['userbin'].two_factor_verify(params[:code])
15
+
15
16
  set_flash_message :notice, :success
16
17
  redirect_to after_sign_in_path_for(scope)
17
18
  rescue Userbin::UserUnauthorizedError => error
@@ -21,7 +22,7 @@ class Devise::DeviseUserbinController < DeviseController
21
22
  rescue Userbin::Forbidden => error
22
23
  sign_out_with_message(:no_retries_remaining, :alert)
23
24
  rescue Userbin::Error => error
24
- sign_out_with_message(:alert, :alert)
25
+ sign_out_with_message(:error, :alert)
25
26
  end
26
27
  end
27
28
  end
@@ -2,7 +2,6 @@ class Devise::SecuritySettingsController < DeviseController
2
2
  include Devise::Controllers::Helpers
3
3
 
4
4
  def show
5
- session_token = session["#{resource_name}_userbin"]
6
- redirect_to Userbin.security_settings_url(session_token)
5
+ redirect_to env['userbin'].security_settings_url
7
6
  end
8
7
  end
@@ -6,11 +6,6 @@ require 'devise_userbin/hooks'
6
6
  require 'devise_userbin/import'
7
7
  require 'userbin'
8
8
 
9
- if defined?(Rails::Railtie)
10
- require 'devise_userbin/railtie'
11
- Rails::Engine
12
- end
13
-
14
9
  module Devise
15
10
  mattr_accessor :userbin_api_secret
16
11
  @@userbin_api_secret = ''
@@ -25,6 +20,11 @@ module DeviseUserbin
25
20
  end
26
21
  end
27
22
 
23
+ if defined?(Rails::Railtie)
24
+ require 'devise_userbin/railtie'
25
+ Rails::Engine
26
+ end
27
+
28
28
  Devise.add_module(:userbin,
29
29
  :controller => :two_factor_authentication,
30
30
  :route => :userbin,
@@ -10,11 +10,18 @@ module DeviseUserbin
10
10
  private
11
11
 
12
12
  def handle_two_factor_authentication
13
- unless devise_controller?
13
+ if !devise_controller? && env['userbin'].authorized?
14
14
  Devise.mappings.keys.flatten.any? do |scope|
15
15
  if signed_in?(scope)
16
- if Userbin.two_factor_authenticate!(session["#{scope}_userbin"])
17
- handle_required_two_factor_authentication(scope)
16
+ begin
17
+ factor = env['userbin'].two_factor_authenticate!
18
+
19
+ # Show form and message specific to the current factor
20
+ case factor
21
+ when :authenticator
22
+ handle_required_two_factor_authentication(scope)
23
+ end
24
+ rescue Userbin::Error # ignore for now
18
25
  end
19
26
  end
20
27
  end
@@ -1,34 +1,26 @@
1
+ Warden::Manager.on_request do |warden|
2
+ warden.request.env['userbin'] = Userbin::Client.new(warden.request)
3
+ end
4
+
1
5
  # Everytime current_<scope> is prepared
2
6
  #
3
7
  Warden::Manager.after_set_user :only => :fetch do |record, warden, opts|
4
- scope = opts[:scope]
5
-
6
- begin
7
- session_token = warden.request.session["#{scope}_userbin"]
8
-
9
- session_token =
10
- Userbin.authenticate(session_token, record._userbin_id, {
11
- properties: {
12
- email: record.email
13
- },
14
- context: {
15
- ip: warden.request.ip,
16
- user_agent: warden.request.user_agent
17
- }
18
- })
19
-
20
- warden.request.session["#{scope}_userbin"] = session_token
21
-
22
- rescue Userbin::Error => error
23
- warden.logout(scope)
24
- throw :warden, :scope => scope, :message => :timeout
8
+ if record.respond_to?(:_userbin_id)
9
+ begin
10
+ userbin = warden.request.env['userbin']
11
+ userbin.authorize!(record._userbin_id, { email: record.email })
12
+ rescue Userbin::Error
13
+ warden.logout(opts[:scope])
14
+ throw :warden, :scope => opts[:scope], :message => :timeout
15
+ end
25
16
  end
26
-
27
17
  end
28
18
 
29
19
  Warden::Manager.before_logout do |record, warden, opts|
30
- begin
31
- session_token = warden.request.session.delete("#{opts[:scope]}_userbin")
32
- Userbin.deauthenticate(session_token)
33
- rescue Userbin::Error; end
20
+ if record.respond_to?(:userbin_id)
21
+ begin
22
+ userbin = warden.request.env['userbin']
23
+ userbin.logout
24
+ rescue Userbin::Error; end
25
+ end
34
26
  end
@@ -17,9 +17,8 @@
17
17
  def userbin_user_block
18
18
  begin
19
19
  yield
20
- rescue ::Userbin::Error => error
21
- self.errors[:base] << error.to_s
22
- false
20
+ rescue ::Userbin::Error
21
+ true
23
22
  end
24
23
  end
25
24
 
@@ -1,3 +1,3 @@
1
1
  module DeviseUserbin
2
- VERSION = "0.1.3".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_userbin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Brissmyr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-21 00:00:00.000000000 Z
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.3
33
+ version: 1.1.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.3
40
+ version: 1.1.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement