google-authenticator-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/README.md +8 -6
- data/google-authenticator.gemspec +3 -3
- data/lib/google-authenticator-rails/active_record/acts_as_google_authenticated.rb +3 -1
- data/lib/google-authenticator-rails/active_record/google_authentication.rb +1 -1
- data/lib/google-authenticator-rails/version.rb +1 -1
- data/spec/google_authenticator_spec.rb +18 -6
- metadata +12 -11
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.8.7
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
# - jruby-18mode # JRuby in 1.8 mode
|
7
|
+
# - 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
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
Ï# Google::Authenticator
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/jaredonline/google-authenticator.png)](http://travis-ci.org/jaredonline/google-authenticator)
|
2
4
|
|
3
5
|
Rails (ActiveRecord) integration with the Google Authenticator apps for Android and the iPhone.
|
4
6
|
|
@@ -55,26 +57,26 @@ class User
|
|
55
57
|
acts_as_google_authenticated :method => :user_name_with_label
|
56
58
|
|
57
59
|
def user_name_with_label
|
58
|
-
"#{user_name}@
|
60
|
+
"#{user_name}@example.com"
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
62
64
|
@user = User.new(:user_name => "ted")
|
63
|
-
@user.google_label # => "ted@
|
65
|
+
@user.google_label # => "ted@example.com"
|
64
66
|
|
65
67
|
class User
|
66
68
|
acts_as_google_authenticated :method => Proc.new { |user| user.user_name_with_label.upcase }
|
67
69
|
|
68
70
|
def user_name_with_label
|
69
|
-
"#{user_name}@
|
71
|
+
"#{user_name}@example.com"
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
73
75
|
@user = User.new(:user_name => "ted")
|
74
|
-
@user.google_label # => "TED@
|
76
|
+
@user.google_label # => "TED@EXAMPLE.COM"
|
75
77
|
```
|
76
78
|
|
77
|
-
You can also
|
79
|
+
You can also specify a column for storing the google secret. The default is `google_secret`.
|
78
80
|
|
79
81
|
Example
|
80
82
|
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["jared.online@gmail.com"]
|
7
7
|
gem.description = %q{Add the ability to use the Google Authenticator with ActiveRecord.}
|
8
8
|
gem.summary = %q{Add the ability to use the Google Authenticator with ActiveRecord.}
|
9
|
-
gem.homepage = "http://github.com/jaredonline/google-authenticator
|
9
|
+
gem.homepage = "http://github.com/jaredonline/google-authenticator"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -15,9 +15,9 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Google::Authenticator::Rails::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency "activesupport"
|
18
|
+
gem.add_dependency "activesupport"
|
19
19
|
gem.add_dependency "rotp"
|
20
|
-
gem.add_dependency "activerecord"
|
20
|
+
gem.add_dependency "activerecord"
|
21
21
|
gem.add_dependency "google-qr"
|
22
22
|
|
23
23
|
gem.add_development_dependency "rspec", "~> 2.8.0"
|
@@ -15,12 +15,14 @@ module ActiveRecord # :nodoc:
|
|
15
15
|
# it supercedes :column_name
|
16
16
|
# [:google_secret_column] the column the secret will be stored in, defaults
|
17
17
|
# to "google_secret"
|
18
|
+
# [:skip_attr_accessible] defaults to false, if set to true will no call
|
19
|
+
# attr_accessible on the google_secret_column
|
18
20
|
def acts_as_google_authenticated(options = {})
|
19
21
|
@google_label_column = options[:column_name] || :email
|
20
22
|
@google_label_method = options[:method] || :default_google_label_method
|
21
23
|
@google_secret_column = options[:google_secret_column] || :google_secret
|
22
24
|
|
23
|
-
attr_accessible @google_secret_column
|
25
|
+
attr_accessible @google_secret_column unless options[:skip_attr_accessible] == true
|
24
26
|
|
25
27
|
[:google_label_column, :google_label_method, :google_secret_column].each do |cattr|
|
26
28
|
self.class.__send__(:define_method, cattr) do
|
@@ -9,7 +9,7 @@ module ActiveRecord # :nodoc:
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def google_qr_uri
|
12
|
-
GoogleQR.new(data
|
12
|
+
GoogleQR.new(:data => ROTP::TOTP.new(google_secret_value).provisioning_uri(google_label), :size => "200x200").to_s
|
13
13
|
end
|
14
14
|
|
15
15
|
def google_label
|
@@ -43,7 +43,7 @@ describe Google::Authenticator::Rails do
|
|
43
43
|
before do
|
44
44
|
time = Time.parse("2012-08-07 11:11:00 AM +0700")
|
45
45
|
Time.stub!(:now).and_return(time)
|
46
|
-
@user = User.create(email
|
46
|
+
@user = User.create(:email => "test@example.com", :user_name => "test_user")
|
47
47
|
@user.google_secret = "test"
|
48
48
|
end
|
49
49
|
|
@@ -68,10 +68,22 @@ describe Google::Authenticator::Rails do
|
|
68
68
|
@user.google_secret.should == "5qlcip7azyjuwm36"
|
69
69
|
end
|
70
70
|
|
71
|
+
context 'skip_attr_accessible' do
|
72
|
+
it 'respects the :skip_attr_accessible flag' do
|
73
|
+
User.should_not_receive(:attr_accessible).with(:google_secret)
|
74
|
+
User.acts_as_google_authenticated :skip_attr_accessible => true
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'respects the default' do
|
78
|
+
User.should_receive(:attr_accessible).with(:google_secret)
|
79
|
+
User.acts_as_google_authenticated
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
71
83
|
context 'secret column' do
|
72
84
|
before do
|
73
85
|
Google::Authenticator::Rails.stub!(:generate_secret).and_return("test")
|
74
|
-
@user = CustomUser.create(email
|
86
|
+
@user = CustomUser.create(:email => "test@example.com", :user_name => "test_user")
|
75
87
|
@user.set_google_secret!
|
76
88
|
end
|
77
89
|
|
@@ -80,7 +92,7 @@ describe Google::Authenticator::Rails do
|
|
80
92
|
end
|
81
93
|
|
82
94
|
it 'generates a url for a qr code' do
|
83
|
-
@user.google_qr_uri.should == "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%
|
95
|
+
@user.google_qr_uri.should == "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%40example.com%3Fsecret%3Dtest&chs=200x200"
|
84
96
|
end
|
85
97
|
end
|
86
98
|
|
@@ -88,7 +100,7 @@ describe Google::Authenticator::Rails do
|
|
88
100
|
|
89
101
|
it 'generates a url for a qr code' do
|
90
102
|
@user.set_google_secret!
|
91
|
-
@user.google_qr_uri.should == "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%
|
103
|
+
@user.google_qr_uri.should == "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%40example.com%3Fsecret%3D5qlcip7azyjuwm36&chs=200x200"
|
92
104
|
end
|
93
105
|
|
94
106
|
it 'can generate off any column' do
|
@@ -106,13 +118,13 @@ describe Google::Authenticator::Rails do
|
|
106
118
|
it 'can generate with a method symbol' do
|
107
119
|
@user.class.acts_as_google_authenticated :method => :email
|
108
120
|
@user.set_google_secret!
|
109
|
-
@user.google_qr_uri.should == "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%
|
121
|
+
@user.google_qr_uri.should == "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%40example.com%3Fsecret%3D5qlcip7azyjuwm36&chs=200x200"
|
110
122
|
end
|
111
123
|
|
112
124
|
it 'can generate with a method string' do
|
113
125
|
@user.class.acts_as_google_authenticated :method => "email"
|
114
126
|
@user.set_google_secret!
|
115
|
-
@user.google_qr_uri.should == "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%
|
127
|
+
@user.google_qr_uri.should == "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%40example.com%3Fsecret%3D5qlcip7azyjuwm36&chs=200x200"
|
116
128
|
end
|
117
129
|
|
118
130
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-authenticator-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rotp
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,17 +48,17 @@ dependencies:
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: '0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: google-qr
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +116,7 @@ extra_rdoc_files: []
|
|
116
116
|
files:
|
117
117
|
- .gitignore
|
118
118
|
- .rspec
|
119
|
+
- .travis.yml
|
119
120
|
- Gemfile
|
120
121
|
- LICENSE
|
121
122
|
- README.md
|
@@ -131,7 +132,7 @@ files:
|
|
131
132
|
- lib/google-authenticator-rails/version.rb
|
132
133
|
- spec/google_authenticator_spec.rb
|
133
134
|
- spec/spec_helper.rb
|
134
|
-
homepage: http://github.com/jaredonline/google-authenticator
|
135
|
+
homepage: http://github.com/jaredonline/google-authenticator
|
135
136
|
licenses: []
|
136
137
|
post_install_message:
|
137
138
|
rdoc_options: []
|