google-authenticator-rails 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ google-auth-rails
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p484
data/.travis.yml CHANGED
@@ -3,9 +3,9 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.2
5
5
  - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
6
8
  # - jruby-18mode # JRuby in 1.8 mode
7
9
  # - jruby-19mode # JRuby in 1.9 mode
8
- - rbx-18mode
9
- - rbx-19mode
10
- # uncomment this line if your project needs to run something other than `rake`:
11
- script: bundle exec rspec spec
10
+ # - rbx-18mode
11
+ # - rbx-19mode
data/Appraisals ADDED
@@ -0,0 +1,23 @@
1
+ version_info = RUBY_VERSION.split(".")
2
+
3
+ major = version_info.first.to_i
4
+ minor = version_info[1].to_i
5
+ hotfix = version_info.last.to_i
6
+
7
+ if major < 2
8
+ appraise "rails2.3" do
9
+ gem "activerecord", "~> 2.3.8"
10
+ end
11
+ end
12
+
13
+ appraise "rails3.0" do
14
+ gem "activerecord", "~> 3.0.0"
15
+ end
16
+
17
+ appraise "rails3.1" do
18
+ gem "activerecord", "~> 3.1.0"
19
+ end
20
+
21
+ appraise "rails3.2." do
22
+ gem "activerecord", "~> 3.2.0"
23
+ end
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/google-authenticator-rails.png)](http://badge.fury.io/rb/google-authenticator-rails)
4
4
  [![Build Status](https://secure.travis-ci.org/jaredonline/google-authenticator.png)](http://travis-ci.org/jaredonline/google-authenticator)
5
+ [![Code Climate](https://codeclimate.com/repos/52d87827e30ba05abf0010c8/badges/a5a86d94e894763e190a/gpa.png)](https://codeclimate.com/repos/52d87827e30ba05abf0010c8/feed)
5
6
 
6
7
  Rails (ActiveRecord) integration with the Google Authenticator apps for Android and the iPhone. Uses the Authlogic style for cookie management.
7
8
 
data/Rakefile CHANGED
@@ -1,2 +1,28 @@
1
1
  #!/usr/bin/env rake
2
+ require "bundler/setup"
2
3
  require "bundler/gem_tasks"
4
+ require "appraisal"
5
+
6
+ begin
7
+ # RSpec 2
8
+ require "rspec/core/rake_task"
9
+
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.pattern = "spec/**/*_spec.rb"
12
+ t.rspec_opts = "--color --format documentation --backtrace"
13
+ end
14
+ rescue LoadError
15
+ # RSpec 1
16
+ require "spec/rake/spectask"
17
+
18
+ Spec::Rake::SpecTask.new(:spec) do |t|
19
+ t.pattern = "spec/**/*_spec.rb"
20
+ t.spec_opts = ["--color", "--format nested", "--backtrace"]
21
+ end
22
+ end
23
+
24
+ desc "Default: Test the gem under all supported Rails versions."
25
+ task :default => ["appraisal:install"] do
26
+ exec("rake appraisal spec")
27
+ end
28
+
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 2.3.8"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ google-authenticator-rails (0.0.6)
5
+ actionpack
6
+ activerecord (< 4.0.0)
7
+ google-qr
8
+ rotp (= 1.4.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionpack (2.3.18)
14
+ activesupport (= 2.3.18)
15
+ rack (~> 1.1.0)
16
+ activerecord (2.3.18)
17
+ activesupport (= 2.3.18)
18
+ activesupport (2.3.18)
19
+ appraisal (0.5.2)
20
+ bundler
21
+ rake
22
+ diff-lcs (1.1.3)
23
+ google-qr (0.2.2)
24
+ rack (1.1.6)
25
+ rake (10.1.1)
26
+ rotp (1.4.1)
27
+ rspec (2.8.0)
28
+ rspec-core (~> 2.8.0)
29
+ rspec-expectations (~> 2.8.0)
30
+ rspec-mocks (~> 2.8.0)
31
+ rspec-core (2.8.0)
32
+ rspec-expectations (2.8.0)
33
+ diff-lcs (~> 1.1.2)
34
+ rspec-mocks (2.8.0)
35
+ sqlite3 (1.3.8)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ activerecord (~> 2.3.8)
42
+ appraisal (~> 0.5.1)
43
+ google-authenticator-rails!
44
+ rspec (~> 2.8.0)
45
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.0.0"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ google-authenticator-rails (0.0.6)
5
+ actionpack
6
+ activerecord (< 4.0.0)
7
+ google-qr
8
+ rotp (= 1.4.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ abstract (1.0.0)
14
+ actionpack (3.0.20)
15
+ activemodel (= 3.0.20)
16
+ activesupport (= 3.0.20)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.5.0)
20
+ rack (~> 1.2.5)
21
+ rack-mount (~> 0.6.14)
22
+ rack-test (~> 0.5.7)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.20)
25
+ activesupport (= 3.0.20)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.5.0)
28
+ activerecord (3.0.20)
29
+ activemodel (= 3.0.20)
30
+ activesupport (= 3.0.20)
31
+ arel (~> 2.0.10)
32
+ tzinfo (~> 0.3.23)
33
+ activesupport (3.0.20)
34
+ appraisal (0.5.2)
35
+ bundler
36
+ rake
37
+ arel (2.0.10)
38
+ builder (2.1.2)
39
+ diff-lcs (1.1.3)
40
+ erubis (2.6.6)
41
+ abstract (>= 1.0.0)
42
+ google-qr (0.2.2)
43
+ i18n (0.5.3)
44
+ rack (1.2.8)
45
+ rack-mount (0.6.14)
46
+ rack (>= 1.0.0)
47
+ rack-test (0.5.7)
48
+ rack (>= 1.0)
49
+ rake (10.1.1)
50
+ rotp (1.4.1)
51
+ rspec (2.8.0)
52
+ rspec-core (~> 2.8.0)
53
+ rspec-expectations (~> 2.8.0)
54
+ rspec-mocks (~> 2.8.0)
55
+ rspec-core (2.8.0)
56
+ rspec-expectations (2.8.0)
57
+ diff-lcs (~> 1.1.2)
58
+ rspec-mocks (2.8.0)
59
+ sqlite3 (1.3.8)
60
+ tzinfo (0.3.38)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ activerecord (~> 3.0.0)
67
+ appraisal (~> 0.5.1)
68
+ google-authenticator-rails!
69
+ rspec (~> 2.8.0)
70
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.1.0"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ google-authenticator-rails (0.0.6)
5
+ actionpack
6
+ activerecord (< 4.0.0)
7
+ google-qr
8
+ rotp (= 1.4.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionpack (3.1.12)
14
+ activemodel (= 3.1.12)
15
+ activesupport (= 3.1.12)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ i18n (~> 0.6)
19
+ rack (~> 1.3.6)
20
+ rack-cache (~> 1.2)
21
+ rack-mount (~> 0.8.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.0.4)
24
+ activemodel (3.1.12)
25
+ activesupport (= 3.1.12)
26
+ builder (~> 3.0.0)
27
+ i18n (~> 0.6)
28
+ activerecord (3.1.12)
29
+ activemodel (= 3.1.12)
30
+ activesupport (= 3.1.12)
31
+ arel (~> 2.2.3)
32
+ tzinfo (~> 0.3.29)
33
+ activesupport (3.1.12)
34
+ multi_json (~> 1.0)
35
+ appraisal (0.5.2)
36
+ bundler
37
+ rake
38
+ arel (2.2.3)
39
+ builder (3.0.4)
40
+ diff-lcs (1.1.3)
41
+ erubis (2.7.0)
42
+ google-qr (0.2.2)
43
+ hike (1.2.3)
44
+ i18n (0.6.9)
45
+ multi_json (1.8.4)
46
+ rack (1.3.10)
47
+ rack-cache (1.2)
48
+ rack (>= 0.4)
49
+ rack-mount (0.8.3)
50
+ rack (>= 1.0.0)
51
+ rack-test (0.6.2)
52
+ rack (>= 1.0)
53
+ rake (10.1.1)
54
+ rotp (1.4.1)
55
+ rspec (2.8.0)
56
+ rspec-core (~> 2.8.0)
57
+ rspec-expectations (~> 2.8.0)
58
+ rspec-mocks (~> 2.8.0)
59
+ rspec-core (2.8.0)
60
+ rspec-expectations (2.8.0)
61
+ diff-lcs (~> 1.1.2)
62
+ rspec-mocks (2.8.0)
63
+ sprockets (2.0.4)
64
+ hike (~> 1.2)
65
+ rack (~> 1.0)
66
+ tilt (~> 1.1, != 1.3.0)
67
+ sqlite3 (1.3.8)
68
+ tilt (1.4.1)
69
+ tzinfo (0.3.38)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ activerecord (~> 3.1.0)
76
+ appraisal (~> 0.5.1)
77
+ google-authenticator-rails!
78
+ rspec (~> 2.8.0)
79
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.0"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ google-authenticator-rails (0.0.6)
5
+ actionpack
6
+ activerecord (< 4.0.0)
7
+ google-qr
8
+ rotp (= 1.4.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionpack (3.2.13)
14
+ activemodel (= 3.2.13)
15
+ activesupport (= 3.2.13)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.4)
19
+ rack (~> 1.4.5)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.13)
24
+ activesupport (= 3.2.13)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.13)
27
+ activemodel (= 3.2.13)
28
+ activesupport (= 3.2.13)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activesupport (3.2.13)
32
+ i18n (= 0.6.1)
33
+ multi_json (~> 1.0)
34
+ appraisal (0.5.2)
35
+ bundler
36
+ rake
37
+ arel (3.0.2)
38
+ builder (3.0.4)
39
+ diff-lcs (1.1.3)
40
+ erubis (2.7.0)
41
+ google-qr (0.2.2)
42
+ hike (1.2.3)
43
+ i18n (0.6.1)
44
+ journey (1.0.4)
45
+ multi_json (1.8.4)
46
+ rack (1.4.5)
47
+ rack-cache (1.2)
48
+ rack (>= 0.4)
49
+ rack-test (0.6.2)
50
+ rack (>= 1.0)
51
+ rake (10.1.1)
52
+ rotp (1.4.1)
53
+ rspec (2.8.0)
54
+ rspec-core (~> 2.8.0)
55
+ rspec-expectations (~> 2.8.0)
56
+ rspec-mocks (~> 2.8.0)
57
+ rspec-core (2.8.0)
58
+ rspec-expectations (2.8.0)
59
+ diff-lcs (~> 1.1.2)
60
+ rspec-mocks (2.8.0)
61
+ sprockets (2.2.2)
62
+ hike (~> 1.2)
63
+ multi_json (~> 1.0)
64
+ rack (~> 1.0)
65
+ tilt (~> 1.1, != 1.3.0)
66
+ sqlite3 (1.3.8)
67
+ tilt (1.4.1)
68
+ tzinfo (0.3.38)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ activerecord (~> 3.2.0)
75
+ appraisal (~> 0.5.1)
76
+ google-authenticator-rails!
77
+ rspec (~> 2.8.0)
78
+ sqlite3
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.0.0"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ google-authenticator-rails (0.0.6)
5
+ actionpack
6
+ activerecord
7
+ google-qr
8
+ rotp (= 1.4.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionpack (4.0.2)
14
+ activesupport (= 4.0.2)
15
+ builder (~> 3.1.0)
16
+ erubis (~> 2.7.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ activemodel (4.0.2)
20
+ activesupport (= 4.0.2)
21
+ builder (~> 3.1.0)
22
+ activerecord (4.0.2)
23
+ activemodel (= 4.0.2)
24
+ activerecord-deprecated_finders (~> 1.0.2)
25
+ activesupport (= 4.0.2)
26
+ arel (~> 4.0.0)
27
+ activerecord-deprecated_finders (1.0.3)
28
+ activesupport (4.0.2)
29
+ i18n (~> 0.6, >= 0.6.4)
30
+ minitest (~> 4.2)
31
+ multi_json (~> 1.3)
32
+ thread_safe (~> 0.1)
33
+ tzinfo (~> 0.3.37)
34
+ appraisal (0.5.2)
35
+ bundler
36
+ rake
37
+ arel (4.0.1)
38
+ atomic (1.1.14)
39
+ builder (3.1.4)
40
+ diff-lcs (1.1.3)
41
+ erubis (2.7.0)
42
+ google-qr (0.2.2)
43
+ i18n (0.6.9)
44
+ minitest (4.7.5)
45
+ multi_json (1.8.4)
46
+ rack (1.5.2)
47
+ rack-test (0.6.2)
48
+ rack (>= 1.0)
49
+ rake (10.1.1)
50
+ rotp (1.4.1)
51
+ rspec (2.8.0)
52
+ rspec-core (~> 2.8.0)
53
+ rspec-expectations (~> 2.8.0)
54
+ rspec-mocks (~> 2.8.0)
55
+ rspec-core (2.8.0)
56
+ rspec-expectations (2.8.0)
57
+ diff-lcs (~> 1.1.2)
58
+ rspec-mocks (2.8.0)
59
+ sqlite3 (1.3.8)
60
+ thread_safe (0.1.3)
61
+ atomic
62
+ tzinfo (0.3.38)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ activerecord (~> 4.0.0)
69
+ appraisal (~> 0.5.1)
70
+ google-authenticator-rails!
71
+ rspec (~> 2.8.0)
72
+ sqlite3
@@ -1,6 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require File.expand_path('../lib/google-authenticator-rails/version', __FILE__)
3
3
 
4
+ version_info = RUBY_VERSION.split(".")
5
+
6
+ major = version_info.first.to_i
7
+ minor = version_info[1].to_i
8
+ hotfix = version_info.last.to_i
9
+
4
10
  Gem::Specification.new do |gem|
5
11
  gem.authors = ["Jared McFarland"]
6
12
  gem.email = ["jared.online@gmail.com"]
@@ -20,6 +26,7 @@ Gem::Specification.new do |gem|
20
26
  gem.add_dependency "google-qr"
21
27
  gem.add_dependency "actionpack"
22
28
 
23
- gem.add_development_dependency "rspec", "~> 2.8.0"
29
+ gem.add_development_dependency "rspec", "~> 2.8.0"
30
+ gem.add_development_dependency "appraisal", "~> 0.5.1"
24
31
  gem.add_development_dependency "sqlite3"
25
32
  end
@@ -1,5 +1,5 @@
1
1
  # Stuff the gem requireds
2
- #
2
+ #
3
3
  require 'active_support'
4
4
  require 'active_record'
5
5
  require 'openssl'
@@ -12,7 +12,7 @@ GOOGLE_AUTHENTICATOR_RAILS_PATH = File.dirname(__FILE__) + "/google-authenticato
12
12
 
13
13
  [
14
14
  "version",
15
-
15
+
16
16
  "action_controller",
17
17
  "active_record",
18
18
  "session"
@@ -21,7 +21,7 @@ GOOGLE_AUTHENTICATOR_RAILS_PATH = File.dirname(__FILE__) + "/google-authenticato
21
21
  end
22
22
 
23
23
  # Sets up some basic accessors for use with the ROTP module
24
- #
24
+ #
25
25
  module GoogleAuthenticatorRails
26
26
  # Drift is set to 6 because ROTP drift is not inclusive. This allows a drift of 5 seconds.
27
27
  DRIFT = 6
@@ -52,4 +52,4 @@ module GoogleAuthenticatorRails
52
52
  def self.time_until_expiration=(time_until_expiration)
53
53
  @@time_until_expiration = time_until_expiration
54
54
  end
55
- end
55
+ end
@@ -1,88 +1,91 @@
1
1
  module GoogleAuthenticatorRails # :nodoc:
2
- module ActiveRecord # :nodoc:
2
+ module ActiveRecord # :nodoc:
3
3
  module ActsAsGoogleAuthenticated # :nodoc:
4
4
  def self.included(base)
5
5
  base.extend ClassMethods
6
6
  end
7
7
 
8
8
  # This is the single integration point. Monkey patch ActiveRecord::Base
9
- # to include the ActsAsGoogleAuthenticated module, which allows a user
9
+ # to include the ActsAsGoogleAuthenticated module, which allows a user
10
10
  # to call User.acts_as_google_authenticated.
11
- #
11
+ #
12
12
  # The model being used must have a string column named "google_secret", or an explicitly
13
13
  # named column.
14
- #
14
+ #
15
15
  # Example:
16
- #
16
+ #
17
17
  # class User
18
18
  # acts_as_google_authenticated
19
19
  # end
20
- #
20
+ #
21
21
  # @user = user.new
22
22
  # @user.set_google_secret # => true
23
23
  # @user.google_qr_uri # => http://path.to.google/qr?with=params
24
24
  # @user.google_authentic?(123456) # => true
25
- #
25
+ #
26
26
  # Google Labels
27
27
  # When setting up an account with the GoogleAuthenticator you need to provide
28
28
  # a label for that account (to distinguish it from other accounts).
29
- #
29
+ #
30
30
  # GoogleAuthenticatorRails allows you to customize how the record will create
31
31
  # that label. There are three options:
32
32
  # - The default just uses the column "email" on the model
33
33
  # - You can specify a custom column with the :column_name option
34
34
  # - You can specify a custom method via a symbol or a proc
35
- #
35
+ #
36
36
  # Examples:
37
- #
37
+ #
38
38
  # class User
39
39
  # acts_as_google_authenticated :column => :user_name
40
40
  # end
41
- #
41
+ #
42
42
  # @user = User.new(:user_name => "ted")
43
43
  # @user.google_label # => "ted"
44
- #
44
+ #
45
45
  # class User
46
46
  # acts_as_google_authenticated :method => :user_name_with_label
47
- #
47
+ #
48
48
  # def user_name_with_label
49
49
  # "#{user_name}@example.com"
50
50
  # end
51
51
  # end
52
- #
52
+ #
53
53
  # @user = User.new(:user_name => "ted")
54
54
  # @user.google_label # => "ted@example.com"
55
- #
55
+ #
56
56
  # class User
57
57
  # acts_as_google_authenticated :method => Proc.new { |user| user.user_name_with_label.upcase }
58
- #
58
+ #
59
59
  # def user_name_with_label
60
60
  # "#{user_name}@example.com"
61
61
  # end
62
62
  # end
63
- #
63
+ #
64
64
  # @user = User.new(:user_name => "ted")
65
65
  # @user.google_label # => "TED@EXAMPLE.COM"
66
- #
66
+ #
67
67
  module ClassMethods # :nodoc
68
68
 
69
- # Initializes the class attributes with the specified options and includes the
69
+ # Initializes the class attributes with the specified options and includes the
70
70
  # respective ActiveRecord helper methods
71
- #
71
+ #
72
72
  # Options:
73
73
  # [:column_name] the name of the column used to create the google_label
74
74
  # [:method] name of the method to call to create the google_label
75
75
  # it supercedes :column_name
76
76
  # [:google_secret_column] the column the secret will be stored in, defaults
77
77
  # to "google_secret"
78
+ # [:lookup_token] the column to use to find the record from the DB, defaults
79
+ # to "persistence_token"
78
80
  def acts_as_google_authenticated(options = {})
79
81
  @google_label_column = options[:column_name] || :email
80
82
  @google_label_method = options[:method] || :default_google_label_method
81
83
  @google_secret_column = options[:google_secret_column] || :google_secret
84
+ @google_lookup_token = options[:lookup_token] || :persistence_token
82
85
 
83
86
  puts ":skip_attr_accessible is no longer required. Called from #{Kernel.caller[0]}}" if options.has_key?(:skip_attr_accessible)
84
87
 
85
- [:google_label_column, :google_label_method, :google_secret_column].each do |cattr|
88
+ [:google_label_column, :google_label_method, :google_secret_column, :google_lookup_token].each do |cattr|
86
89
  self.singleton_class.class_eval { attr_reader cattr }
87
90
  end
88
91
 
@@ -38,6 +38,10 @@ module GoogleAuthenticatorRails # :nodoc:
38
38
  end
39
39
  end
40
40
 
41
+ def google_token_value
42
+ self.__send__(self.class.google_lookup_token)
43
+ end
44
+
41
45
  private
42
46
  def default_google_label_method
43
47
  self.__send__(self.class.google_label_column)
@@ -16,7 +16,7 @@ module GoogleAuthenticatorRails
16
16
  cookie = controller.cookies[cookie_key]
17
17
  if cookie
18
18
  token, user_id = parse_cookie(cookie).values_at(:token, :user_id)
19
- conditions = { :persistence_token => token, :id => user_id }
19
+ conditions = { klass.google_lookup_token => token, :id => user_id }
20
20
  record = __send__(finder, conditions).first
21
21
  session = new(record)
22
22
  session.valid? ? session : nil
@@ -26,8 +26,8 @@ module GoogleAuthenticatorRails
26
26
  end
27
27
 
28
28
  def create(user)
29
- raise GoogleAuthenticatorRails::Session::Persistence::TokenNotFound if !user.respond_to?(:persistence_token) || user.persistence_token.blank?
30
- controller.cookies[cookie_key] = create_cookie(user.persistence_token, user.id)
29
+ raise GoogleAuthenticatorRails::Session::Persistence::TokenNotFound if user.nil? || !user.respond_to?(user.class.google_lookup_token) || user.google_token_value.blank?
30
+ controller.cookies[cookie_key] = create_cookie(user.google_token_value, user.id)
31
31
  new(user)
32
32
  end
33
33
 
@@ -72,4 +72,4 @@ module GoogleAuthenticatorRails
72
72
  end
73
73
  end
74
74
  end
75
- end
75
+ end
@@ -1,7 +1,7 @@
1
1
  module Google
2
2
  module Authenticator
3
3
  module Rails
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
6
6
  end
7
7
  end
@@ -5,10 +5,10 @@ describe GoogleAuthenticatorRails do
5
5
  before do
6
6
  ROTP::Base32.stub!(:random_base32).and_return(random32)
7
7
  end
8
-
8
+
9
9
  describe '#generate_password' do
10
10
  subject { GoogleAuthenticatorRails::generate_password("test", counter) }
11
-
11
+
12
12
  context 'counter = 1' do
13
13
  let(:counter) { 1 }
14
14
  it { should == 812658 }
@@ -19,7 +19,7 @@ describe GoogleAuthenticatorRails do
19
19
  it { should == 73348 }
20
20
  end
21
21
  end
22
-
22
+
23
23
  context 'time-based passwords' do
24
24
  let(:time) { Time.parse("2012-08-07 11:11:11 AM +0700") }
25
25
  let(:secret) { "test" }
@@ -27,16 +27,16 @@ describe GoogleAuthenticatorRails do
27
27
  before { Time.stub!(:now).and_return(time) }
28
28
 
29
29
  specify { GoogleAuthenticatorRails::time_based_password(secret).should == code }
30
- specify { GoogleAuthenticatorRails::valid?(code, secret).should be true }
30
+ specify { GoogleAuthenticatorRails::valid?(code, secret).should be true }
31
31
 
32
32
  specify { GoogleAuthenticatorRails::valid?(code * 2, secret).should be false }
33
- specify { GoogleAuthenticatorRails::valid?(code, secret * 2).should be false }
33
+ specify { GoogleAuthenticatorRails::valid?(code, secret * 2).should be false }
34
34
  end
35
-
35
+
36
36
  it 'can create a secret' do
37
37
  GoogleAuthenticatorRails::generate_secret.should == random32
38
38
  end
39
-
39
+
40
40
  context 'integration with ActiveRecord' do
41
41
  let(:original_time) { Time.parse("2012-08-07 11:11:00 AM +0700") }
42
42
  let(:time) { original_time }
@@ -45,7 +45,7 @@ describe GoogleAuthenticatorRails do
45
45
  @user = User.create(:email => "test@example.com", :user_name => "test_user")
46
46
  @user.google_secret = "test"
47
47
  end
48
-
48
+
49
49
  context 'code validation' do
50
50
  subject { @user.google_authentic?(472374) }
51
51
 
@@ -61,7 +61,7 @@ describe GoogleAuthenticatorRails do
61
61
  it { should be false }
62
62
  end
63
63
  end
64
-
64
+
65
65
  it 'creates a secret' do
66
66
  @user.set_google_secret
67
67
  @user.google_secret.should == random32
@@ -96,12 +96,12 @@ describe GoogleAuthenticatorRails do
96
96
  subject { user.google_qr_uri }
97
97
 
98
98
  it { should eq "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%40example.com%3Fsecret%3D5qlcip7azyjuwm36&chs=200x200" }
99
-
99
+
100
100
  context 'custom column name' do
101
101
  let(:user) { ColumnNameUser.create options }
102
102
  it { should eq "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest_user%3Fsecret%3D5qlcip7azyjuwm36&chs=200x200" }
103
103
  end
104
-
104
+
105
105
  context 'custom proc' do
106
106
  let(:user) { ProcUser.create options }
107
107
  it { should eq "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest_user%40futureadvisor-admin%3Fsecret%3D5qlcip7azyjuwm36&chs=200x200" }
@@ -112,12 +112,12 @@ describe GoogleAuthenticatorRails do
112
112
  it { should eq "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%40example.com%3Fsecret%3D5qlcip7azyjuwm36&chs=200x200" }
113
113
  end
114
114
 
115
- context 'method defined by string' do
115
+ context 'method defined by string' do
116
116
  let(:user) { StringUser.create options }
117
117
  it { should eq "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%40example.com%3Fsecret%3D5qlcip7azyjuwm36&chs=200x200" }
118
- end
118
+ end
119
119
  end
120
-
120
+
121
121
  end
122
-
123
- end
122
+
123
+ end
@@ -16,16 +16,25 @@ describe GoogleAuthenticatorRails::Session::Base do
16
16
  end
17
17
 
18
18
  context 'session' do
19
- before { set_cookie_for(user) }
20
- after { clear_cookie }
19
+ before { set_cookie_for(user) unless user.nil? }
20
+ after { clear_cookie unless user.nil? }
21
21
 
22
22
  it { should be_a UserMfaSession }
23
23
  its(:record) { should eq user }
24
+
25
+ context 'custom lookup token' do
26
+ let(:user) { SaltUser.create(:password => "password", :email => "email@example.com") }
27
+
28
+ subject { SaltUserMfaSession.find }
29
+
30
+ it { should be_a SaltUserMfaSession }
31
+ its(:record) { should eq user }
32
+ end
24
33
  end
25
34
  end
26
35
 
27
36
  describe '::create' do
28
- after { clear_cookie }
37
+ after { clear_cookie unless user.nil? }
29
38
  subject { UserMfaSession.create(user) }
30
39
 
31
40
  it { should be_a UserMfaSession }
@@ -50,9 +59,13 @@ describe GoogleAuthenticatorRails::Session::Base do
50
59
  end
51
60
 
52
61
  def set_cookie_for(user)
53
- controller.cookies[UserMfaSession.__send__(:cookie_key)] = { :value => [user.persistence_token, user.id].join('::'), :expires => nil }
62
+ controller.cookies[klass(user).__send__(:cookie_key)] = { :value => [user.google_token_value, user.id].join('::'), :expires => nil }
63
+ end
64
+
65
+ def klass(user)
66
+ "#{user.class.to_s}MfaSession".constantize unless user.nil?
54
67
  end
55
68
 
56
69
  def clear_cookie
57
- controller.cookies[UserMfaSession.__send__(:cookie_key)] = nil
58
- end
70
+ controller.cookies[klass(user).__send__(:cookie_key)] = nil
71
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,8 @@ require 'time'
2
2
  require 'active_record'
3
3
  require 'action_controller'
4
4
  require 'rotp'
5
+ require 'bundler'
6
+ require 'bundler/setup'
5
7
 
6
8
  require 'google-authenticator-rails'
7
9
 
@@ -55,6 +57,7 @@ ActiveRecord::Schema.define do
55
57
  t.string :user_name
56
58
  t.string :password
57
59
  t.string :persistence_token
60
+ t.string :salt
58
61
 
59
62
  t.timestamps
60
63
  end
@@ -64,6 +67,7 @@ ActiveRecord::Schema.define do
64
67
  t.string :email
65
68
  t.string :user_name
66
69
  t.string :persistence_token
70
+ t.string :salt
67
71
 
68
72
  t.timestamps
69
73
  end
@@ -71,10 +75,12 @@ end
71
75
 
72
76
  class BaseUser < ActiveRecord::Base
73
77
  attr_accessible :email, :user_name, :password
78
+
74
79
  self.table_name = "users"
75
80
 
76
81
  before_save do |user|
77
82
  user.persistence_token ||= "token"
83
+ user.salt ||= "salt"
78
84
  end
79
85
  end
80
86
 
@@ -106,3 +112,9 @@ end
106
112
  class StringUser < BaseUser
107
113
  acts_as_google_authenticated :method => "email"
108
114
  end
115
+
116
+ class SaltUserMfaSession < GoogleAuthenticatorRails::Session::Base; end
117
+
118
+ class SaltUser < BaseUser
119
+ acts_as_google_authenticated :lookup_token => :salt
120
+ end
metadata CHANGED
@@ -1,127 +1,159 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: google-authenticator-rails
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.6
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 7
10
+ version: 0.0.7
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Jared McFarland
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2014-01-16 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rotp
16
- requirement: !ruby/object:Gem::Requirement
17
+
18
+ date: 2014-01-17 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
17
22
  none: false
18
- requirements:
19
- - - '='
20
- - !ruby/object:Gem::Version
23
+ requirements:
24
+ - - "="
25
+ - !ruby/object:Gem::Version
26
+ hash: 5
27
+ segments:
28
+ - 1
29
+ - 4
30
+ - 1
21
31
  version: 1.4.1
22
- type: :runtime
23
32
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - '='
28
- - !ruby/object:Gem::Version
29
- version: 1.4.1
30
- - !ruby/object:Gem::Dependency
31
- name: activerecord
32
- requirement: !ruby/object:Gem::Requirement
33
+ type: :runtime
34
+ name: rotp
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
33
38
  none: false
34
- requirements:
39
+ requirements:
35
40
  - - <
36
- - !ruby/object:Gem::Version
41
+ - !ruby/object:Gem::Version
42
+ hash: 63
43
+ segments:
44
+ - 4
45
+ - 0
46
+ - 0
37
47
  version: 4.0.0
38
- type: :runtime
39
48
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
49
+ type: :runtime
50
+ name: activerecord
51
+ requirement: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
41
54
  none: false
42
- requirements:
43
- - - <
44
- - !ruby/object:Gem::Version
45
- version: 4.0.0
46
- - !ruby/object:Gem::Dependency
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ prerelease: false
63
+ type: :runtime
47
64
  name: google-qr
48
- requirement: !ruby/object:Gem::Requirement
65
+ requirement: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
49
68
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
55
76
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: actionpack
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
77
  type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: rspec
80
- requirement: !ruby/object:Gem::Requirement
78
+ name: actionpack
79
+ requirement: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
81
82
  none: false
82
- requirements:
83
+ requirements:
83
84
  - - ~>
84
- - !ruby/object:Gem::Version
85
+ - !ruby/object:Gem::Version
86
+ hash: 47
87
+ segments:
88
+ - 2
89
+ - 8
90
+ - 0
85
91
  version: 2.8.0
86
- type: :development
87
92
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
93
+ type: :development
94
+ name: rspec
95
+ requirement: *id005
96
+ - !ruby/object:Gem::Dependency
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
89
98
  none: false
90
- requirements:
99
+ requirements:
91
100
  - - ~>
92
- - !ruby/object:Gem::Version
93
- version: 2.8.0
94
- - !ruby/object:Gem::Dependency
95
- name: sqlite3
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :development
101
+ - !ruby/object:Gem::Version
102
+ hash: 9
103
+ segments:
104
+ - 0
105
+ - 5
106
+ - 1
107
+ version: 0.5.1
103
108
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
109
+ type: :development
110
+ name: appraisal
111
+ requirement: *id006
112
+ - !ruby/object:Gem::Dependency
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
105
114
  none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ prerelease: false
123
+ type: :development
124
+ name: sqlite3
125
+ requirement: *id007
110
126
  description: Add the ability to use the Google Authenticator with ActiveRecord.
111
- email:
127
+ email:
112
128
  - jared.online@gmail.com
113
129
  executables: []
130
+
114
131
  extensions: []
132
+
115
133
  extra_rdoc_files: []
116
- files:
134
+
135
+ files:
117
136
  - .gitignore
118
137
  - .rspec
138
+ - .ruby-gemset
139
+ - .ruby-version
119
140
  - .travis.yml
141
+ - Appraisals
120
142
  - CONTRIBUTING.md
121
143
  - Gemfile
122
144
  - LICENSE
123
145
  - README.md
124
146
  - Rakefile
147
+ - gemfiles/rails2.3.gemfile
148
+ - gemfiles/rails2.3.gemfile.lock
149
+ - gemfiles/rails3.0.gemfile
150
+ - gemfiles/rails3.0.gemfile.lock
151
+ - gemfiles/rails3.1.gemfile
152
+ - gemfiles/rails3.1.gemfile.lock
153
+ - gemfiles/rails3.2..gemfile
154
+ - gemfiles/rails3.2..gemfile.lock
155
+ - gemfiles/rails4.0.gemfile
156
+ - gemfiles/rails4.0.gemfile.lock
125
157
  - google-authenticator.gemspec
126
158
  - lib/google-authenticator-rails.rb
127
159
  - lib/google-authenticator-rails/action_controller.rb
@@ -142,33 +174,41 @@ files:
142
174
  - spec/spec_helper.rb
143
175
  homepage: http://github.com/jaredonline/google-authenticator
144
176
  licenses: []
177
+
145
178
  post_install_message:
146
179
  rdoc_options: []
147
- require_paths:
180
+
181
+ require_paths:
148
182
  - lib
149
- required_ruby_version: !ruby/object:Gem::Requirement
183
+ required_ruby_version: !ruby/object:Gem::Requirement
150
184
  none: false
151
- requirements:
152
- - - ! '>='
153
- - !ruby/object:Gem::Version
154
- version: '0'
155
- required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ hash: 3
189
+ segments:
190
+ - 0
191
+ version: "0"
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
193
  none: false
157
- requirements:
158
- - - ! '>='
159
- - !ruby/object:Gem::Version
160
- version: '0'
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ hash: 3
198
+ segments:
199
+ - 0
200
+ version: "0"
161
201
  requirements: []
202
+
162
203
  rubyforge_project:
163
204
  rubygems_version: 1.8.24
164
205
  signing_key:
165
206
  specification_version: 3
166
207
  summary: Add the ability to use the Google Authenticator with ActiveRecord.
167
- test_files:
208
+ test_files:
168
209
  - spec/action_controller/integration_spec.rb
169
210
  - spec/action_controller/rails_adapter_spec.rb
170
211
  - spec/google_authenticator_spec.rb
171
212
  - spec/session/activation_spec.rb
172
213
  - spec/session/persistance_spec.rb
173
214
  - spec/spec_helper.rb
174
- has_rdoc: