devise-otp 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +36 -0
  3. data/.gitignore +0 -0
  4. data/Gemfile +1 -22
  5. data/LICENSE.txt +0 -0
  6. data/README.md +41 -74
  7. data/Rakefile +0 -0
  8. data/app/assets/javascripts/devise-otp.js +1 -0
  9. data/app/assets/javascripts/qrcode.js +609 -0
  10. data/app/controllers/devise_otp/devise/credentials_controller.rb +102 -0
  11. data/app/controllers/devise_otp/devise/tokens_controller.rb +112 -0
  12. data/app/views/devise/credentials/refresh.html.erb +19 -0
  13. data/app/views/devise/credentials/show.html.erb +31 -0
  14. data/app/views/devise/tokens/_token_secret.html.erb +23 -0
  15. data/app/views/devise/tokens/_trusted_devices.html.erb +12 -0
  16. data/app/views/devise/tokens/recovery.html.erb +21 -0
  17. data/app/views/devise/tokens/recovery_codes.text.erb +3 -0
  18. data/app/views/devise/tokens/show.html.erb +21 -0
  19. data/config/locales/en.yml +8 -8
  20. data/devise-otp.gemspec +14 -9
  21. data/docs/QR_CODES.md +48 -0
  22. data/lib/devise-otp/version.rb +1 -1
  23. data/lib/devise-otp.rb +12 -11
  24. data/lib/devise_otp_authenticatable/controllers/helpers.rb +20 -12
  25. data/lib/devise_otp_authenticatable/controllers/url_helpers.rb +6 -7
  26. data/lib/devise_otp_authenticatable/engine.rb +22 -13
  27. data/lib/devise_otp_authenticatable/hooks/sessions.rb +8 -7
  28. data/lib/devise_otp_authenticatable/hooks.rb +1 -1
  29. data/lib/devise_otp_authenticatable/models/otp_authenticatable.rb +14 -9
  30. data/lib/devise_otp_authenticatable/routes.rb +4 -7
  31. data/lib/generators/active_record/devise_otp_generator.rb +0 -0
  32. data/lib/generators/active_record/templates/migration.rb +1 -1
  33. data/lib/generators/devise_otp/devise_otp_generator.rb +0 -0
  34. data/lib/generators/devise_otp/install_generator.rb +8 -5
  35. data/lib/generators/devise_otp/views_generator.rb +2 -3
  36. data/test/dummy/README.rdoc +0 -0
  37. data/test/dummy/Rakefile +0 -0
  38. data/test/dummy/app/assets/config/manifest.js +2 -0
  39. data/test/dummy/app/assets/javascripts/application.js +1 -0
  40. data/test/dummy/app/assets/stylesheets/application.css +0 -0
  41. data/test/dummy/app/controllers/application_controller.rb +1 -1
  42. data/test/dummy/app/controllers/posts_controller.rb +2 -0
  43. data/test/dummy/app/helpers/application_helper.rb +0 -0
  44. data/test/dummy/app/helpers/posts_helper.rb +0 -0
  45. data/test/dummy/app/mailers/.gitkeep +0 -0
  46. data/test/dummy/app/models/post.rb +0 -0
  47. data/test/dummy/app/models/user.rb +0 -0
  48. data/test/dummy/app/views/layouts/application.html.erb +0 -0
  49. data/test/dummy/app/views/posts/_form.html.erb +0 -0
  50. data/test/dummy/app/views/posts/edit.html.erb +0 -0
  51. data/test/dummy/app/views/posts/index.html.erb +0 -0
  52. data/test/dummy/app/views/posts/new.html.erb +0 -0
  53. data/test/dummy/app/views/posts/show.html.erb +0 -0
  54. data/test/dummy/config/application.rb +2 -1
  55. data/test/dummy/config/boot.rb +0 -0
  56. data/test/dummy/config/database.yml +1 -1
  57. data/test/dummy/config/environment.rb +0 -0
  58. data/test/dummy/config/environments/development.rb +0 -7
  59. data/test/dummy/config/environments/production.rb +0 -4
  60. data/test/dummy/config/environments/test.rb +0 -0
  61. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -0
  62. data/test/dummy/config/initializers/devise.rb +0 -0
  63. data/test/dummy/config/initializers/inflections.rb +0 -0
  64. data/test/dummy/config/initializers/mime_types.rb +0 -0
  65. data/test/dummy/config/initializers/secret_token.rb +0 -0
  66. data/test/dummy/config/initializers/session_store.rb +0 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +0 -0
  68. data/test/dummy/config/locales/en.yml +0 -0
  69. data/test/dummy/config/routes.rb +0 -0
  70. data/test/dummy/config.ru +0 -0
  71. data/test/dummy/db/migrate/20130125101430_create_users.rb +1 -1
  72. data/test/dummy/db/migrate/20130131092406_add_devise_to_users.rb +1 -1
  73. data/test/dummy/db/migrate/20130131142320_create_posts.rb +1 -1
  74. data/test/dummy/db/migrate/20130131160351_devise_otp_add_to_users.rb +2 -2
  75. data/test/dummy/db/test.sqlite3-journal +0 -0
  76. data/test/dummy/lib/assets/.gitkeep +0 -0
  77. data/test/dummy/public/404.html +0 -0
  78. data/test/dummy/public/422.html +0 -0
  79. data/test/dummy/public/500.html +0 -0
  80. data/test/dummy/public/favicon.ico +0 -0
  81. data/test/integration/persistence_test.rb +18 -2
  82. data/test/integration/refresh_test.rb +2 -32
  83. data/test/integration/sign_in_test.rb +3 -3
  84. data/test/integration/token_test.rb +1 -4
  85. data/test/integration_tests_helper.rb +0 -1
  86. data/test/model_tests_helper.rb +0 -0
  87. data/test/models/otp_authenticatable_test.rb +8 -9
  88. data/test/orm/active_record.rb +3 -1
  89. data/test/test_helper.rb +71 -2
  90. metadata +146 -40
  91. data/.travis.yml +0 -12
  92. data/app/controllers/devise_otp/credentials_controller.rb +0 -106
  93. data/app/controllers/devise_otp/tokens_controller.rb +0 -105
  94. data/app/views/devise_otp/credentials/refresh.html.erb +0 -20
  95. data/app/views/devise_otp/credentials/show.html.erb +0 -23
  96. data/app/views/devise_otp/tokens/_token_secret.html.erb +0 -17
  97. data/app/views/devise_otp/tokens/_trusted_devices.html.erb +0 -10
  98. data/app/views/devise_otp/tokens/recovery.html.erb +0 -21
  99. data/app/views/devise_otp/tokens/show.html.erb +0 -19
  100. data/lib/devise_otp_authenticatable/mapping.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a79f472f1aa5f902585f4e0d9fba2be6acd49c4d
4
- data.tar.gz: ae454d13216e89de407336b54572276958d1c7b6
2
+ SHA256:
3
+ metadata.gz: 6b5132454cb31efb85ab78d8a0866c6e98e3e3fc8f9c51fa770b735e59a0d976
4
+ data.tar.gz: ef69e79487527616462f0c3c918094a9338ede9b59a8aef005b34549ae231166
5
5
  SHA512:
6
- metadata.gz: 850c7c8ce55daf8a956f5d281f3e3be67030c543f7d91872e1009216c57f5dc8e56a381f287b862c1b994117a06fe5fc836829b3dc759c9ce12564c2743bb711
7
- data.tar.gz: 425351d1ac147a529daf7a45d07456f8bc49697134ecaf6495bb42100f2b5cc451720620d461291fbdcde4c3b8e70cb61eb4b31d192cbabdd28f637883e7df5d
6
+ metadata.gz: 7312e301fb3a313056878b4e7d067ed78ad37717fbb632b27e9dce05d7bd77e8b972bdbcb8ff189800509ef65d74c99773c650cebc881756d5c9a5456b0c2578
7
+ data.tar.gz: 7e1f0bb51e8c805f6e95eb4cc61231e3bcfd9562ac0c523ee3f60221cea9b56891f42badb66ed7b3bc986fec63cd9164100b72822d26ede99fda7a7029f29f38
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: CI
3
+
4
+ on:
5
+ - push
6
+ - pull_request
7
+
8
+ jobs:
9
+ rspec:
10
+ runs-on: ubuntu-20.04
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ ruby:
15
+ - '3.1'
16
+ - '3.0'
17
+ - '2.7'
18
+
19
+ steps:
20
+ - name: Checkout
21
+ uses: actions/checkout@v2
22
+
23
+ - name: Setup Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+
28
+ - name: Bundle
29
+ run: |
30
+ gem install bundler
31
+ bundle install --jobs 4 --retry 3
32
+
33
+ - name: Run tests
34
+ env:
35
+ DEVISE_ORM: active_record
36
+ run: rake test
data/.gitignore CHANGED
File without changes
data/Gemfile CHANGED
@@ -1,25 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in devise-otp.gemspec
4
4
  gemspec
5
-
6
- gem "rdoc"
7
-
8
- group :test do
9
- platforms :jruby do
10
- gem 'activerecord-jdbcsqlite3-adapter'
11
- end
12
-
13
- platforms :ruby do
14
- gem "sqlite3"
15
- end
16
-
17
- gem "rails", "~> 4.0.0"
18
-
19
- gem "capybara"
20
- gem 'shoulda'
21
- gem 'selenium-webdriver'
22
-
23
- gem 'minitest-reporters', '>= 0.5.0'
24
-
25
- end
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -1,41 +1,38 @@
1
1
  # Devise::Otp
2
- [![Build Status](https://travis-ci.org/wmlele/devise-otp.png?branch=master)](https://travis-ci.org/wmlele/devise-otp)
3
2
 
4
- Devise OTP implements two-factors authentication for Devise, using an rfc6238 compatible Time-Based One-Time Password Algorithm.
5
- It uses the [rotp library](https://github.com/mdp/rotp) for generation and verification of codes.
3
+ Devise OTP is a two-factors authentication extension for Devise. The second factor is done using an [RFC 6238](https://datatracker.ietf.org/doc/html/rfc6238) Time-Based One-Time Password (TOTP) implemented by the [rotp library](https://github.com/mdp/rotp).
6
4
 
7
- **If you are upgrading from version 0.1.x, you will need to regenerate your views.**
5
+ It has the following features:
8
6
 
9
- It currently has the following features:
7
+ - Optional and mandatory OTP enforcement
8
+ - Setting up trusted browsers for limited access
9
+ - Generating QR codes
10
10
 
11
- * Url based provisioning of token devices, compatible with **Google Authenticator**.
12
- * Browsers can be set as 'trusted' for a limited time. During that time no OTP challenge is asked again when logging from that browser (but normal login will).
13
- * Two factors authentication can be **optional** at user discretion, **recommended** (it nags the user on every sign-in) or **mandatory** (users must enroll OTP after signing-in next time, before they can navigate the site). The settings is global, or per-user. ( **incomplete**, see below)
14
- * Optionally, users can obtain a list of HOTP recovery tokens to be used for emergency log-in in case the token device is lost or unavailable.
15
-
16
- Compatible token devices are:
11
+ Some of the compatible token devices are:
17
12
 
18
13
  * [Google Authenticator](https://code.google.com/p/google-authenticator/)
19
14
  * [FreeOTP](https://fedorahosted.org/freeotp/)
20
15
 
21
- ## Quick overview of Two Factors Authentication, using OTPs.
16
+ Device OTP was recently updated to work with Rails 7 and Turbo.
17
+
18
+ ## Two-factors authentication using OTP
22
19
 
23
- * A shared secret is generated on the server, and stored both on the token device (ie: the phone) and the server itself.
20
+ * A shared secret is generated on the server, and stored both on the token device (e.g. the phone) and the server itself.
24
21
  * The secret is used to generate short numerical tokens that are either time or sequence based.
25
22
  * Tokens can be generated on a phone without internet connectivity.
26
23
  * The token provides an additional layer of security against password theft.
27
24
  * OTP's should always be used as a second factor of authentication(if your phone is lost, you account is still secured with a password)
28
25
  * Google Authenticator allows you to store multiple OTP secrets and provision those using a QR Code
29
26
 
30
- Although there's an adjustable drift window, it is important that both the server and the token device (phone) have their clocks set (eg: using NTP).
31
-
27
+ *Although there's an adjustable drift window, it is important that both the server and the token device (phone) have their clocks set (eg: using NTP).*
32
28
 
33
29
  ## Installation
34
30
 
35
- Add this line to your application's Gemfile:
31
+ If you haven't, set up [Devise](https://github.com/heartcombo/devise) first.
36
32
 
37
- gem 'devise'
38
- gem 'devise-otp'
33
+ To add Devise OTP, add this line to your application's Gemfile:
34
+
35
+ gem "devise-otp"
39
36
 
40
37
  And then execute:
41
38
 
@@ -45,32 +42,11 @@ Or install it yourself as:
45
42
 
46
43
  $ gem install devise-otp
47
44
 
48
-
49
- ### Devise Installation
50
-
51
- To setup Devise, you need to do the following (but refer to https://github.com/plataformatec/devise for more information)
52
-
53
- Install Devise:
54
-
55
- rails g devise:install
56
-
57
- Setup the User or Admin model
58
-
59
- rails g devise MODEL
60
-
61
- Configure your app for authorisation, edit your Controller and add this before_filter:
62
-
63
- before_filter :authenticate_user!
64
-
65
- Make sure your "root" route is configured in config/routes.rb
66
-
67
- ### Automatic Installation
68
-
69
45
  Run the following generator to add the necessary configuration options to Devise's config file:
70
46
 
71
47
  rails g devise_otp:install
72
48
 
73
- After you've created your Devise user models (which is usually done with a "rails g devise MODEL"), set up your Devise OTP additions:
49
+ After you've created your Devise user models (which is usually done with a `rails g devise MODEL`), set up your Devise OTP additions:
74
50
 
75
51
  rails g devise_otp MODEL
76
52
 
@@ -78,57 +54,48 @@ Don't forget to migrate:
78
54
 
79
55
  rake db:migrate
80
56
 
81
- ### Custom Views
57
+ Add the gem's JavaScript to you `application.js`:
82
58
 
83
- If you want to customise your views (which you likely will want to), you can use the generator:
59
+ //= require devise-otp
84
60
 
85
- rails g devise_otp:views
86
61
 
87
- ### I18n
62
+ ### Custom views
88
63
 
89
- The install generator also installs an english copy of a Devise OTP i18n file. This can be modified (or used to create other language versions) and is located at: _config/locales/devise.otp.en.yml_
64
+ If you want to customise your views, you can use the following generator to eject the default view files:
90
65
 
66
+ rails g devise_otp:views
91
67
 
92
- ## Usage
93
-
94
- With this extension enabled, the following is expected behaviour:
95
-
96
- * Users may go to _/MODEL/otp/token_ and enable their OTP state, they might be asked to provide their password again (and OTP token, if it's enabled)
97
- * Once enabled they're shown an alphanumeric code (for manual provisioning) and a QR code, for automatic provisioning of their authetication device (for instance, Google Authenticator)
98
- * If config.otp_mandatory or model_instance.otp_mandatory, users will be required to enable, and provision, next time they successfully sign-in.
68
+ By default, the files live within the Devise namespace (`app/views/devise`, but if you want to move them or want to match the Devise configuration, set `config.otp_controller_path` in your initializers.
99
69
 
70
+ ### I18n
100
71
 
101
- ### Configuration Options
72
+ The install generator also installs an english copy of a Devise OTP i18n file. This can be modified (or used to create other language versions) and is located at: _config/locales/devise.otp.en.yml_
102
73
 
103
- The install generator adds some options to the end of your Devise config file (config/initializers/devise.rb)
74
+ ### QR codes
104
75
 
105
- * `config.otp_mandatory` - OTP is mandatory, users are going to be asked to enroll the next time they sign in, before they can successfully complete the session establishment.
106
- * `config.otp_authentication_timeout` - how long the user has to authenticate with their token. (defaults to `3.minutes`)
107
- * `config.otp_drift_window` - a window which provides allowance for drift between a user's token device clock (and therefore their OTP tokens) and the authentication server's clock. Expressed in minutes centered at the current time. (default: `3`)
108
- * `config.otp_credentials_refresh` - Users that have logged in longer than this time ago, are going to be asked their password (and an OTP challenge, if enabled) before they can see or change their otp informations. (defaults to `15.minutes`)
109
- * `config.otp_recovery_tokens` - Whether the users are given a list of one-time recovery tokens, for emergency access (default: `10`, set to `false` to disable)
110
- * `config.otp_trust_persistence` - The user is allowed to set his browser as "trusted", no more OTP challenges will be asked for that browser, for a limited time. (default: `1.month`, set to false to disable setting the browser as trusted)
111
- * `config.otp_uri_application` - The name of this application, to be added to the provisioning url as '<user_email>/application_name' (defaults to the Rails application class)
76
+ By default, Devise OTP assumes that you use [Sprockets](https://github.com/rails/sprockets) to render assets and so will use the ([qrcode.js](/app/assets/javascripts/qrcode.js)) embeded library to render the QR code.
112
77
 
113
- ## Todo
78
+ If you need something more, have a look at [QR codes](/docs/QR_CODES.md) documentation file.
114
79
 
115
- * 2D barcodes for provisioning are currently produced with the google charts api. You can, of course, use your own source in the template, but I am looking for a solution with no external dependencies (feedback welcome).
116
- * **recommended** mode (nag the user each time) is not fully implemented. Right now you can make 2FA mandatory, or leave it to the user.
80
+ ## Configuration
117
81
 
82
+ The install generator adds some options to the end of your Devise config file (`config/initializers/devise.rb`):
118
83
 
119
- ## Contributing
84
+ * `config.otp_mandatory`: OTP is mandatory, users are going to be asked to enroll the next time they sign in, before they can successfully complete the session establishment.
85
+ * `config.otp_authentication_timeout`: How long the user has to authenticate with their token. (defaults to `3.minutes`)
86
+ * `config.otp_drift_window`: A window which provides allowance for drift between a user's token device clock (and therefore their OTP tokens) and the authentication server's clock. Expressed in minutes centered at the current time. (default: `3`)
87
+ * `config.otp_credentials_refresh`: Users that have logged in longer than this time ago, are going to be asked their password (and an OTP challenge, if enabled) before they can see or change their otp informations. (defaults to `15.minutes`)
88
+ * `config.otp_recovery_tokens`: Whether the users are given a list of one-time recovery tokens, for emergency access (default: `10`, set to `false` to disable)
89
+ * `config.otp_trust_persistence`: The user is allowed to set his browser as "trusted", no more OTP challenges will be asked for that browser, for a limited time. (default: `1.month`, set to false to disable setting the browser as trusted)
90
+ * `config.otp_issuer`: The name of the token issuer, to be added to the provisioning url. Display will vary based on token application. (defaults to the Rails application class)
91
+ * `config.otp_controller_path`: The view path for Devise OTP controllers. The default being 'devise' to match Devise default installation.
120
92
 
121
- 1. Fork it
122
- 2. Create your feature branch (`git checkout -b my-new-feature`)
123
- 3. Commit your changes (`git commit -am 'Add some feature'`)
124
- 4. Push to the branch (`git push origin my-new-feature`)
125
- 5. Create new Pull Request
93
+ ## Authors
126
94
 
127
- ## Thanks
95
+ The project was originally started by Lele Forzani by forking [devise_google_authenticator](https://github.com/AsteriskLabs/devise_google_authenticator) and still contains some devise_google_authenticator code. It's now maintained by [Josef Strzibny](https://github.com/strzibny/).
128
96
 
129
- I started this extension by forking [devise_google_authenticator](https://github.com/AsteriskLabs/devise_google_authenticator), and this project still contains some chunk of code from it, esp. in the tests and generators.
130
- At some point, my design goals were significantly diverging, so I refactored most of its code. Still, I want to thank the original author for his relevant contribution.
97
+ Contributions are welcome!
131
98
 
132
99
  ## License
133
100
 
134
- MIT Licensed
101
+ MIT Licensed
data/Rakefile CHANGED
File without changes
@@ -0,0 +1 @@
1
+ //= require_tree .