devise-authy 1.0.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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +138 -0
- data/LICENSE.txt +20 -0
- data/README.md +86 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/app/assets/javascripts/devise_authy.js +7 -0
- data/app/assets/stylesheets/devise_authy.css +26 -0
- data/app/assets/stylesheets/devise_authy.sass +23 -0
- data/app/controllers/devise/devise_authy_controller.rb +109 -0
- data/app/views/devise/enable_authy.html.erb +8 -0
- data/app/views/devise/enable_authy.html.haml +8 -0
- data/app/views/devise/verify_authy.html.erb +13 -0
- data/app/views/devise/verify_authy.html.haml +11 -0
- data/app/views/devise/verify_authy_installation.html.erb +10 -0
- data/app/views/devise/verify_authy_installation.html.haml +8 -0
- data/authy-devise-demo/.gitignore +15 -0
- data/authy-devise-demo/Gemfile +39 -0
- data/authy-devise-demo/Gemfile.lock +134 -0
- data/authy-devise-demo/README.md +64 -0
- data/authy-devise-demo/Rakefile +7 -0
- data/authy-devise-demo/app/assets/images/rails.png +0 -0
- data/authy-devise-demo/app/assets/javascripts/application.js +15 -0
- data/authy-devise-demo/app/assets/javascripts/devise_authy.js +7 -0
- data/authy-devise-demo/app/assets/javascripts/welcome.js.coffee +3 -0
- data/authy-devise-demo/app/assets/stylesheets/application.css +13 -0
- data/authy-devise-demo/app/assets/stylesheets/devise_authy.css +26 -0
- data/authy-devise-demo/app/assets/stylesheets/welcome.css.scss +3 -0
- data/authy-devise-demo/app/controllers/application_controller.rb +3 -0
- data/authy-devise-demo/app/controllers/welcome_controller.rb +6 -0
- data/authy-devise-demo/app/helpers/application_helper.rb +2 -0
- data/authy-devise-demo/app/helpers/welcome_helper.rb +2 -0
- data/authy-devise-demo/app/mailers/.gitkeep +0 -0
- data/authy-devise-demo/app/models/.gitkeep +0 -0
- data/authy-devise-demo/app/models/user.rb +11 -0
- data/authy-devise-demo/app/views/devise/devise_authy/enable_authy.html.erb +8 -0
- data/authy-devise-demo/app/views/devise/devise_authy/verify_authy.html.erb +13 -0
- data/authy-devise-demo/app/views/devise/devise_authy/verify_authy_installation.html.erb +10 -0
- data/authy-devise-demo/app/views/layouts/application.html.erb +18 -0
- data/authy-devise-demo/app/views/welcome/index.html.erb +5 -0
- data/authy-devise-demo/config.ru +4 -0
- data/authy-devise-demo/config/application.rb +62 -0
- data/authy-devise-demo/config/boot.rb +6 -0
- data/authy-devise-demo/config/database.yml +25 -0
- data/authy-devise-demo/config/environment.rb +5 -0
- data/authy-devise-demo/config/environments/development.rb +37 -0
- data/authy-devise-demo/config/environments/production.rb +67 -0
- data/authy-devise-demo/config/environments/test.rb +37 -0
- data/authy-devise-demo/config/initializers/authy.rb +1 -0
- data/authy-devise-demo/config/initializers/backtrace_silencers.rb +7 -0
- data/authy-devise-demo/config/initializers/devise.rb +232 -0
- data/authy-devise-demo/config/initializers/inflections.rb +15 -0
- data/authy-devise-demo/config/initializers/mime_types.rb +5 -0
- data/authy-devise-demo/config/initializers/secret_token.rb +7 -0
- data/authy-devise-demo/config/initializers/session_store.rb +8 -0
- data/authy-devise-demo/config/initializers/wrap_parameters.rb +14 -0
- data/authy-devise-demo/config/locales/devise.authy.en.yml +18 -0
- data/authy-devise-demo/config/locales/devise.en.yml +58 -0
- data/authy-devise-demo/config/locales/en.yml +5 -0
- data/authy-devise-demo/config/routes.rb +62 -0
- data/authy-devise-demo/db/migrate/20130409234357_devise_create_users.rb +46 -0
- data/authy-devise-demo/db/migrate/20130409234434_devise_authy_add_to_users.rb +18 -0
- data/authy-devise-demo/db/schema.rb +38 -0
- data/authy-devise-demo/db/seeds.rb +7 -0
- data/authy-devise-demo/lib/assets/.gitkeep +0 -0
- data/authy-devise-demo/lib/tasks/.gitkeep +0 -0
- data/authy-devise-demo/log/.gitkeep +0 -0
- data/authy-devise-demo/public/404.html +26 -0
- data/authy-devise-demo/public/422.html +26 -0
- data/authy-devise-demo/public/500.html +25 -0
- data/authy-devise-demo/public/favicon.ico +0 -0
- data/authy-devise-demo/public/robots.txt +5 -0
- data/authy-devise-demo/script/rails +6 -0
- data/authy-devise-demo/test/fixtures/.gitkeep +0 -0
- data/authy-devise-demo/test/fixtures/users.yml +11 -0
- data/authy-devise-demo/test/functional/.gitkeep +0 -0
- data/authy-devise-demo/test/functional/welcome_controller_test.rb +9 -0
- data/authy-devise-demo/test/integration/.gitkeep +0 -0
- data/authy-devise-demo/test/performance/browsing_test.rb +12 -0
- data/authy-devise-demo/test/test_helper.rb +13 -0
- data/authy-devise-demo/test/unit/.gitkeep +0 -0
- data/authy-devise-demo/test/unit/helpers/welcome_helper_test.rb +4 -0
- data/authy-devise-demo/test/unit/user_test.rb +7 -0
- data/authy-devise-demo/vendor/assets/javascripts/.gitkeep +0 -0
- data/authy-devise-demo/vendor/assets/stylesheets/.gitkeep +0 -0
- data/authy-devise-demo/vendor/plugins/.gitkeep +0 -0
- data/config/locales/en.yml +18 -0
- data/devise-authy.gemspec +223 -0
- data/lib/devise-authy.rb +22 -0
- data/lib/devise-authy/controllers/helpers.rb +39 -0
- data/lib/devise-authy/controllers/view_helpers.rb +36 -0
- data/lib/devise-authy/hooks/authy_authenticatable.rb +7 -0
- data/lib/devise-authy/models/authy_authenticatable.rb +23 -0
- data/lib/devise-authy/rails.rb +11 -0
- data/lib/devise-authy/routes.rb +20 -0
- data/lib/devise-authy/version.rb +3 -0
- data/lib/generators/active_record/devise_authy_generator.rb +13 -0
- data/lib/generators/active_record/templates/migration.rb +18 -0
- data/lib/generators/devise_authy/devise_authy_generator.rb +30 -0
- data/lib/generators/devise_authy/install_generator.rb +64 -0
- data/spec/controllers/devise_authy_controller_spec.rb +85 -0
- data/spec/generators_spec.rb +24 -0
- data/spec/integration/authy_authenticatable.rb +88 -0
- data/spec/models/authy_authenticatable.rb +17 -0
- data/spec/orm/active_record.rb +4 -0
- data/spec/rails_app/Rakefile +10 -0
- data/spec/rails_app/app/assets/images/rails.png +0 -0
- data/spec/rails_app/app/assets/javascripts/application.js +10 -0
- data/spec/rails_app/app/assets/stylesheets/application.css +9 -0
- data/spec/rails_app/app/assets/stylesheets/devise_authy.css +26 -0
- data/spec/rails_app/app/assets/stylesheets/devise_authy.css.scss +26 -0
- data/spec/rails_app/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/spec/rails_app/app/controllers/application_controller.rb +4 -0
- data/spec/rails_app/app/controllers/posts_controller.rb +83 -0
- data/spec/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_app/app/helpers/posts_helper.rb +2 -0
- data/spec/rails_app/app/mailers/.gitkeep +0 -0
- data/spec/rails_app/app/models/.gitkeep +0 -0
- data/spec/rails_app/app/models/post.rb +2 -0
- data/spec/rails_app/app/models/user.rb +9 -0
- data/spec/rails_app/app/views/devise/devise_authy/register.html.erb +10 -0
- data/spec/rails_app/app/views/devise/devise_authy/show.html.erb +10 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +24 -0
- data/spec/rails_app/app/views/posts/_form.html.erb +25 -0
- data/spec/rails_app/app/views/posts/edit.html.erb +6 -0
- data/spec/rails_app/app/views/posts/index.html.erb +27 -0
- data/spec/rails_app/app/views/posts/new.html.erb +5 -0
- data/spec/rails_app/app/views/posts/show.html.erb +15 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/config/application.rb +33 -0
- data/spec/rails_app/config/boot.rb +7 -0
- data/spec/rails_app/config/database.yml +22 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/development.rb +37 -0
- data/spec/rails_app/config/environments/production.rb +67 -0
- data/spec/rails_app/config/environments/test.rb +37 -0
- data/spec/rails_app/config/initializers/authy.rb +3 -0
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_app/config/initializers/devise.rb +237 -0
- data/spec/rails_app/config/initializers/inflections.rb +10 -0
- data/spec/rails_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails_app/config/initializers/secret_token.rb +7 -0
- data/spec/rails_app/config/initializers/session_store.rb +8 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_app/config/locales/devise.authy.en.yml +14 -0
- data/spec/rails_app/config/routes.rb +6 -0
- data/spec/rails_app/db/migrate/20121029205626_devise_create_users.rb +32 -0
- data/spec/rails_app/db/migrate/20121029205627_create_posts.rb +10 -0
- data/spec/rails_app/db/migrate/20121029205628_devise_authy_add_to_users.rb +15 -0
- data/spec/rails_app/db/schema.rb +43 -0
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/script/rails +6 -0
- data/spec/routing/routes_spec.rb +19 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/helpers.rb +28 -0
- metadata +367 -0
data/.document
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/Gemfile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
source "http://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gem "devise"
|
|
4
|
+
gem 'authy'
|
|
5
|
+
|
|
6
|
+
group :development do
|
|
7
|
+
gem "rspec"
|
|
8
|
+
gem "yard"
|
|
9
|
+
gem "rdoc"
|
|
10
|
+
gem "bundler"
|
|
11
|
+
gem "jeweler"
|
|
12
|
+
gem "simplecov"
|
|
13
|
+
gem "sass-rails"
|
|
14
|
+
gem "jquery-rails"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
group :test do
|
|
18
|
+
gem "sqlite3"
|
|
19
|
+
gem 'rspec-rails'
|
|
20
|
+
gem 'database_cleaner'
|
|
21
|
+
gem 'capybara'
|
|
22
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
actionpack (3.2.8)
|
|
5
|
+
activemodel (= 3.2.8)
|
|
6
|
+
activesupport (= 3.2.8)
|
|
7
|
+
builder (~> 3.0.0)
|
|
8
|
+
erubis (~> 2.7.0)
|
|
9
|
+
journey (~> 1.0.4)
|
|
10
|
+
rack (~> 1.4.0)
|
|
11
|
+
rack-cache (~> 1.2)
|
|
12
|
+
rack-test (~> 0.6.1)
|
|
13
|
+
sprockets (~> 2.1.3)
|
|
14
|
+
activemodel (3.2.8)
|
|
15
|
+
activesupport (= 3.2.8)
|
|
16
|
+
builder (~> 3.0.0)
|
|
17
|
+
activesupport (3.2.8)
|
|
18
|
+
i18n (~> 0.6)
|
|
19
|
+
multi_json (~> 1.0)
|
|
20
|
+
addressable (2.3.2)
|
|
21
|
+
authy (1.1.0)
|
|
22
|
+
httpclient
|
|
23
|
+
bcrypt-ruby (3.0.1)
|
|
24
|
+
builder (3.0.4)
|
|
25
|
+
capybara (1.1.2)
|
|
26
|
+
mime-types (>= 1.16)
|
|
27
|
+
nokogiri (>= 1.3.3)
|
|
28
|
+
rack (>= 1.0.0)
|
|
29
|
+
rack-test (>= 0.5.4)
|
|
30
|
+
selenium-webdriver (~> 2.0)
|
|
31
|
+
xpath (~> 0.1.4)
|
|
32
|
+
childprocess (0.3.6)
|
|
33
|
+
ffi (~> 1.0, >= 1.0.6)
|
|
34
|
+
database_cleaner (0.9.1)
|
|
35
|
+
devise (2.1.2)
|
|
36
|
+
bcrypt-ruby (~> 3.0)
|
|
37
|
+
orm_adapter (~> 0.1)
|
|
38
|
+
railties (~> 3.1)
|
|
39
|
+
warden (~> 1.2.1)
|
|
40
|
+
diff-lcs (1.1.3)
|
|
41
|
+
erubis (2.7.0)
|
|
42
|
+
ffi (1.1.5)
|
|
43
|
+
git (1.2.5)
|
|
44
|
+
hike (1.2.1)
|
|
45
|
+
httpclient (2.3.3)
|
|
46
|
+
i18n (0.6.1)
|
|
47
|
+
jeweler (1.8.4)
|
|
48
|
+
bundler (~> 1.0)
|
|
49
|
+
git (>= 1.2.5)
|
|
50
|
+
rake
|
|
51
|
+
rdoc
|
|
52
|
+
journey (1.0.4)
|
|
53
|
+
jquery-rails (2.1.3)
|
|
54
|
+
railties (>= 3.1.0, < 5.0)
|
|
55
|
+
thor (~> 0.14)
|
|
56
|
+
json (1.7.5)
|
|
57
|
+
libwebsocket (0.1.5)
|
|
58
|
+
addressable
|
|
59
|
+
mime-types (1.19)
|
|
60
|
+
multi_json (1.3.6)
|
|
61
|
+
nokogiri (1.5.5)
|
|
62
|
+
orm_adapter (0.4.0)
|
|
63
|
+
rack (1.4.1)
|
|
64
|
+
rack-cache (1.2)
|
|
65
|
+
rack (>= 0.4)
|
|
66
|
+
rack-ssl (1.3.2)
|
|
67
|
+
rack
|
|
68
|
+
rack-test (0.6.2)
|
|
69
|
+
rack (>= 1.0)
|
|
70
|
+
railties (3.2.8)
|
|
71
|
+
actionpack (= 3.2.8)
|
|
72
|
+
activesupport (= 3.2.8)
|
|
73
|
+
rack-ssl (~> 1.3.2)
|
|
74
|
+
rake (>= 0.8.7)
|
|
75
|
+
rdoc (~> 3.4)
|
|
76
|
+
thor (>= 0.14.6, < 2.0)
|
|
77
|
+
rake (0.9.2.2)
|
|
78
|
+
rdoc (3.12)
|
|
79
|
+
json (~> 1.4)
|
|
80
|
+
rspec (2.11.0)
|
|
81
|
+
rspec-core (~> 2.11.0)
|
|
82
|
+
rspec-expectations (~> 2.11.0)
|
|
83
|
+
rspec-mocks (~> 2.11.0)
|
|
84
|
+
rspec-core (2.11.1)
|
|
85
|
+
rspec-expectations (2.11.3)
|
|
86
|
+
diff-lcs (~> 1.1.3)
|
|
87
|
+
rspec-mocks (2.11.3)
|
|
88
|
+
rspec-rails (2.11.0)
|
|
89
|
+
actionpack (>= 3.0)
|
|
90
|
+
activesupport (>= 3.0)
|
|
91
|
+
railties (>= 3.0)
|
|
92
|
+
rspec (~> 2.11.0)
|
|
93
|
+
rubyzip (0.9.9)
|
|
94
|
+
sass (3.2.1)
|
|
95
|
+
sass-rails (3.2.5)
|
|
96
|
+
railties (~> 3.2.0)
|
|
97
|
+
sass (>= 3.1.10)
|
|
98
|
+
tilt (~> 1.3)
|
|
99
|
+
selenium-webdriver (2.25.0)
|
|
100
|
+
childprocess (>= 0.2.5)
|
|
101
|
+
libwebsocket (~> 0.1.3)
|
|
102
|
+
multi_json (~> 1.0)
|
|
103
|
+
rubyzip
|
|
104
|
+
simplecov (0.7.1)
|
|
105
|
+
multi_json (~> 1.0)
|
|
106
|
+
simplecov-html (~> 0.7.1)
|
|
107
|
+
simplecov-html (0.7.1)
|
|
108
|
+
sprockets (2.1.3)
|
|
109
|
+
hike (~> 1.2)
|
|
110
|
+
rack (~> 1.0)
|
|
111
|
+
tilt (~> 1.1, != 1.3.0)
|
|
112
|
+
sqlite3 (1.3.6)
|
|
113
|
+
thor (0.16.0)
|
|
114
|
+
tilt (1.3.3)
|
|
115
|
+
warden (1.2.1)
|
|
116
|
+
rack (>= 1.0)
|
|
117
|
+
xpath (0.1.4)
|
|
118
|
+
nokogiri (~> 1.3)
|
|
119
|
+
yard (0.8.3)
|
|
120
|
+
|
|
121
|
+
PLATFORMS
|
|
122
|
+
ruby
|
|
123
|
+
|
|
124
|
+
DEPENDENCIES
|
|
125
|
+
authy
|
|
126
|
+
bundler
|
|
127
|
+
capybara
|
|
128
|
+
database_cleaner
|
|
129
|
+
devise
|
|
130
|
+
jeweler
|
|
131
|
+
jquery-rails
|
|
132
|
+
rdoc
|
|
133
|
+
rspec
|
|
134
|
+
rspec-rails
|
|
135
|
+
sass-rails
|
|
136
|
+
simplecov
|
|
137
|
+
sqlite3
|
|
138
|
+
yard
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2012 Johanna Mantilla Duque
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Authy Devise
|
|
2
|
+
|
|
3
|
+
This is a [Devise](https://github.com/plataformatec/devise) extension to add Two-Factor Authentication with Authy to your rails application.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Pre-requisites
|
|
7
|
+
|
|
8
|
+
Get an Authy API Key: [https://www.authy.com/signup](https://www.authy.com/signup)
|
|
9
|
+
|
|
10
|
+
## Demo
|
|
11
|
+
|
|
12
|
+
See [https://github.com/authy/authy-devise/tree/master/authy-devise-demo](https://github.com/authy/authy-devise/tree/master/authy-devise-demo)
|
|
13
|
+
|
|
14
|
+
## Getting started
|
|
15
|
+
|
|
16
|
+
First create an initializer in `config/initializer/authy.rb`
|
|
17
|
+
|
|
18
|
+
Authy.api_key = ENV['AUTHY_API_KEY'] || 'your_authy_api_key'
|
|
19
|
+
Authy.api_uri = 'https://api.authy.com/'
|
|
20
|
+
|
|
21
|
+
You can get the `AUTHY_API_KEY` at [https://www.authy.com/signup](https://www.authy.com/signup)
|
|
22
|
+
|
|
23
|
+
Next add the gem to your Gemfile:
|
|
24
|
+
|
|
25
|
+
gem 'devise'
|
|
26
|
+
gem 'devise-authy'
|
|
27
|
+
|
|
28
|
+
And then run `bundle install`
|
|
29
|
+
|
|
30
|
+
Add `Devise Authy` to your App:
|
|
31
|
+
|
|
32
|
+
rails g devise_authy:install
|
|
33
|
+
|
|
34
|
+
--haml: Generate the views in Haml
|
|
35
|
+
--sass: Generate the stylesheets in Sass
|
|
36
|
+
|
|
37
|
+
### Configuring Models
|
|
38
|
+
|
|
39
|
+
Configure your Devise user model:
|
|
40
|
+
|
|
41
|
+
rails g devise_authy [MODEL_NAME]
|
|
42
|
+
|
|
43
|
+
or add the following line to your `User` model
|
|
44
|
+
|
|
45
|
+
devise :authy_authenticatable, :database_authenticatable
|
|
46
|
+
|
|
47
|
+
Change the default routes to point to something sane like:
|
|
48
|
+
|
|
49
|
+
devise_for :users, :path_names => {
|
|
50
|
+
:verify_authy => "/verify-token",
|
|
51
|
+
:enable_authy => "/enable-two-factor",
|
|
52
|
+
:verify_authy_installation => "/verify-installation"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Then run the migrations:
|
|
56
|
+
|
|
57
|
+
rake db:migrate
|
|
58
|
+
|
|
59
|
+
Now whenever a user wants to enable two-factor authentication he can go
|
|
60
|
+
to:
|
|
61
|
+
|
|
62
|
+
http://your-app/users/enable-two-factor
|
|
63
|
+
|
|
64
|
+
And when the user log's in he will be redirected to:
|
|
65
|
+
|
|
66
|
+
http://your-app/users/verify-token
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Custom Views
|
|
70
|
+
|
|
71
|
+
If you want to customise your views, you can modify the files that are located at:
|
|
72
|
+
|
|
73
|
+
app/views/devise/devise_authy/enable_authy.html.erb
|
|
74
|
+
app/views/devise/devise_authy/verify_authy.html.erb
|
|
75
|
+
app/views/devise/devise_authy/verify_authy_installation.html.erb
|
|
76
|
+
|
|
77
|
+
## I18n
|
|
78
|
+
|
|
79
|
+
The install generator also copy a `Devise Authy` i18n file which you can find at:
|
|
80
|
+
|
|
81
|
+
config/locales/devise.authy.en.yml
|
|
82
|
+
|
|
83
|
+
## Copyright
|
|
84
|
+
|
|
85
|
+
Copyright (c) 2013 Authy Inc. See LICENSE.txt for
|
|
86
|
+
further details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'bundler'
|
|
5
|
+
begin
|
|
6
|
+
Bundler.setup(:default, :development)
|
|
7
|
+
rescue Bundler::BundlerError => e
|
|
8
|
+
$stderr.puts e.message
|
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
+
exit e.status_code
|
|
11
|
+
end
|
|
12
|
+
require 'rake'
|
|
13
|
+
|
|
14
|
+
require 'jeweler'
|
|
15
|
+
Jeweler::Tasks.new do |gem|
|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
17
|
+
gem.name = "devise-authy"
|
|
18
|
+
gem.homepage = "http://github.com/senekis/devise-authy"
|
|
19
|
+
gem.license = "MIT"
|
|
20
|
+
gem.summary = %Q{Authy plugin for Devise}
|
|
21
|
+
gem.description = %Q{Authy plugin for Devise}
|
|
22
|
+
gem.email = "support@authy.com"
|
|
23
|
+
gem.authors = ["Authy Inc."]
|
|
24
|
+
# dependencies defined in Gemfile
|
|
25
|
+
end
|
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
|
27
|
+
|
|
28
|
+
require 'rspec/core'
|
|
29
|
+
require 'rspec/core/rake_task'
|
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
36
|
+
spec.rcov = true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
task :default => :spec
|
|
40
|
+
|
|
41
|
+
require 'yard'
|
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.0
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.devise_authy {
|
|
2
|
+
margin-left: auto;
|
|
3
|
+
margin-right: auto;
|
|
4
|
+
width: 350px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
legend {
|
|
8
|
+
display: block;
|
|
9
|
+
width: 100%;
|
|
10
|
+
padding: 0;
|
|
11
|
+
margin-bottom: 20px;
|
|
12
|
+
font-size: 21px;
|
|
13
|
+
line-height: 40px;
|
|
14
|
+
color: #333;
|
|
15
|
+
border-bottom: 1px solid #E5E5E5;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
label,
|
|
19
|
+
input,
|
|
20
|
+
button {
|
|
21
|
+
font-size: 14px;
|
|
22
|
+
font-weight: normal;
|
|
23
|
+
line-height: 20px;
|
|
24
|
+
padding: 8px;
|
|
25
|
+
margin: 8px;
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.devise_authy
|
|
2
|
+
margin-left: auto
|
|
3
|
+
margin-right: auto
|
|
4
|
+
width: 350px
|
|
5
|
+
|
|
6
|
+
legend
|
|
7
|
+
display: block
|
|
8
|
+
width: 100%
|
|
9
|
+
padding: 0
|
|
10
|
+
margin-bottom: 20px
|
|
11
|
+
font-size: 21px
|
|
12
|
+
line-height: 40px
|
|
13
|
+
color: #333
|
|
14
|
+
border-bottom: 1px solid #E5E5E5
|
|
15
|
+
|
|
16
|
+
label,
|
|
17
|
+
input,
|
|
18
|
+
button
|
|
19
|
+
font-size: 14px
|
|
20
|
+
font-weight: normal
|
|
21
|
+
line-height: 20px
|
|
22
|
+
padding: 8px
|
|
23
|
+
margin: 8px
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
class Devise::DeviseAuthyController < DeviseController
|
|
2
|
+
prepend_before_filter :find_resource_and_require_password_checked, :only => [
|
|
3
|
+
:GET_verify_authy, :POST_verify_authy
|
|
4
|
+
]
|
|
5
|
+
prepend_before_filter :authenticate_scope!, :only => [
|
|
6
|
+
:GET_enable_authy, :POST_enable_authy,
|
|
7
|
+
:GET_verify_authy_installation, :POST_verify_authy_installation
|
|
8
|
+
]
|
|
9
|
+
include Devise::Controllers::Helpers
|
|
10
|
+
|
|
11
|
+
def GET_verify_authy
|
|
12
|
+
@authy_id = @resource.authy_id
|
|
13
|
+
render :verify_authy
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# verify 2fa
|
|
17
|
+
def POST_verify_authy
|
|
18
|
+
token = Authy::API.verify({
|
|
19
|
+
:id => @resource.authy_id,
|
|
20
|
+
:token => params[:token],
|
|
21
|
+
:force => true
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
if token.ok?
|
|
25
|
+
@resource.update_attribute(:last_sign_in_with_authy, DateTime.now)
|
|
26
|
+
|
|
27
|
+
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
|
28
|
+
sign_in(resource_name, @resource)
|
|
29
|
+
respond_with resource, :location => after_sign_in_path_for(@resource)
|
|
30
|
+
else
|
|
31
|
+
render :verify_authy
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# enable 2fa
|
|
36
|
+
def GET_enable_authy
|
|
37
|
+
render :enable_authy
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def POST_enable_authy
|
|
41
|
+
@authy_user = Authy::API.register_user(
|
|
42
|
+
:email => resource.email,
|
|
43
|
+
:cellphone => params[:cellphone],
|
|
44
|
+
:country_code => params[:country_code]
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
if @authy_user.ok?
|
|
48
|
+
resource.authy_id = @authy_user.id
|
|
49
|
+
if resource.save
|
|
50
|
+
set_flash_message(:notice, :enabled)
|
|
51
|
+
else
|
|
52
|
+
set_flash_message(:error, :not_enabled)
|
|
53
|
+
redirect_to :root and return
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
redirect_to [resource_name, :verify_authy_installation]
|
|
57
|
+
else
|
|
58
|
+
set_flash_message(:error, :not_enabled)
|
|
59
|
+
render :enable_authy
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def GET_verify_authy_installation
|
|
64
|
+
render :verify_authy_installation
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def POST_verify_authy_installation
|
|
68
|
+
token = Authy::API.verify({
|
|
69
|
+
:id => self.resource.authy_id,
|
|
70
|
+
:token => params[:token],
|
|
71
|
+
:force => true
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
self.resource.authy_enabled = token.ok?
|
|
75
|
+
if !token.ok? || !self.resource.save
|
|
76
|
+
set_flash_message(:error, :not_enabled)
|
|
77
|
+
render :verify_authy_installation
|
|
78
|
+
else
|
|
79
|
+
set_flash_message(:notice, :enabled)
|
|
80
|
+
redirect_to :root
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def request_sms
|
|
85
|
+
@resource = resource_class.find_by_id(session["#{resource_name}_id"])
|
|
86
|
+
if !@resource
|
|
87
|
+
render :json => {:sent => false, :message => "User couldn't be found."}
|
|
88
|
+
return
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
response = Authy::API.request_sms(:id => @resource.id, :force => true)
|
|
92
|
+
render :json => {:sent => response.ok?, :message => response.message}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
|
|
97
|
+
def authenticate_scope!
|
|
98
|
+
send(:"authenticate_#{resource_name}!", :force => true)
|
|
99
|
+
self.resource = send("current_#{resource_name}")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def find_resource_and_require_password_checked
|
|
103
|
+
@resource = resource_class.find_by_id(session["#{resource_name}_id"])
|
|
104
|
+
|
|
105
|
+
if @resource.nil? || session[:"#{resource_name}_password_checked"].to_s != "true"
|
|
106
|
+
redirect_to :root
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|