devise-otp 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) 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 +43 -66
  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 +10 -10
  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 +22 -14
  24. data/lib/devise_otp_authenticatable/controllers/helpers.rb +29 -16
  25. data/lib/devise_otp_authenticatable/controllers/url_helpers.rb +6 -9
  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 +28 -28
  30. data/lib/devise_otp_authenticatable/routes.rb +9 -10
  31. data/lib/generators/active_record/devise_otp_generator.rb +1 -1
  32. data/lib/generators/active_record/templates/migration.rb +1 -2
  33. data/lib/generators/devise_otp/devise_otp_generator.rb +0 -0
  34. data/lib/generators/devise_otp/install_generator.rb +30 -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 +1 -1
  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 +81 -0
  82. data/test/integration/refresh_test.rb +2 -18
  83. data/test/integration/sign_in_test.rb +14 -4
  84. data/test/integration/token_test.rb +31 -0
  85. data/test/integration_tests_helper.rb +19 -2
  86. data/test/model_tests_helper.rb +0 -0
  87. data/test/models/otp_authenticatable_test.rb +14 -9
  88. data/test/orm/active_record.rb +3 -1
  89. data/test/test_helper.rb +71 -2
  90. metadata +135 -24
  91. data/.travis.yml +0 -11
  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/recovery.html.erb +0 -21
  98. data/app/views/devise_otp/tokens/show.html.erb +0 -31
  99. data/lib/devise_otp_authenticatable/mapping.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 68e7b6bff6340dae80c51a03b25daa473524eee4
4
- data.tar.gz: 1407a2855ebf8bd2df27e678bf1b360922e894eb
2
+ SHA256:
3
+ metadata.gz: 6b5132454cb31efb85ab78d8a0866c6e98e3e3fc8f9c51fa770b735e59a0d976
4
+ data.tar.gz: ef69e79487527616462f0c3c918094a9338ede9b59a8aef005b34549ae231166
5
5
  SHA512:
6
- metadata.gz: 4f233eb0d98a0ec858a27711f355d7ab6306d358b0f0ea80008616c06904ad917b7becfe6f988f51b930627bb6126fa8cc3d23e73b2deb8588fe10d2e963a454
7
- data.tar.gz: fab7310046129c7f095493f0505a3b1b16906608165f0ee446c6afc3980b34e9a0683da2553ac9cec7c80baa409a09305b7abd68c985e4d397384a9d57471a38
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,38 +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
- It currently has the following features:
5
+ It has the following features:
8
6
 
9
- * Url based provisioning of token devices, compatible with **Google Authenticator**.
10
- * 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.
11
- * 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.
7
+ - Optional and mandatory OTP enforcement
8
+ - Setting up trusted browsers for limited access
9
+ - Generating QR codes
12
10
 
13
- Compatible token devices are:
11
+ Some of the compatible token devices are:
14
12
 
15
13
  * [Google Authenticator](https://code.google.com/p/google-authenticator/)
16
- * ...
14
+ * [FreeOTP](https://fedorahosted.org/freeotp/)
17
15
 
18
- ## Quick overview of Two Factors Authentication, using OTPs.
16
+ Device OTP was recently updated to work with Rails 7 and Turbo.
19
17
 
20
- * A shared secret is generated on the server, and stored both on the token device (ie: the phone) and the server itself.
18
+ ## Two-factors authentication using OTP
19
+
20
+ * A shared secret is generated on the server, and stored both on the token device (e.g. the phone) and the server itself.
21
21
  * The secret is used to generate short numerical tokens that are either time or sequence based.
22
22
  * Tokens can be generated on a phone without internet connectivity.
23
23
  * The token provides an additional layer of security against password theft.
24
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)
25
25
  * Google Authenticator allows you to store multiple OTP secrets and provision those using a QR Code
26
26
 
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).
28
-
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).*
29
28
 
30
29
  ## Installation
31
30
 
32
- Add this line to your application's Gemfile:
31
+ If you haven't, set up [Devise](https://github.com/heartcombo/devise) first.
32
+
33
+ To add Devise OTP, add this line to your application's Gemfile:
33
34
 
34
- gem 'devise'
35
- gem 'devise-otp'
35
+ gem "devise-otp"
36
36
 
37
37
  And then execute:
38
38
 
@@ -42,32 +42,11 @@ Or install it yourself as:
42
42
 
43
43
  $ gem install devise-otp
44
44
 
45
-
46
- ### Devise Installation
47
-
48
- To setup Devise, you need to do the following (but refer to https://github.com/plataformatec/devise for more information)
49
-
50
- Install Devise:
51
-
52
- rails g devise:install
53
-
54
- Setup the User or Admin model
55
-
56
- rails g devise MODEL
57
-
58
- Configure your app for authorisation, edit your Controller and add this before_filter:
59
-
60
- before_filter :authenticate_user!
61
-
62
- Make sure your "root" route is configured in config/routes.rb
63
-
64
- ### Automatic Installation
65
-
66
45
  Run the following generator to add the necessary configuration options to Devise's config file:
67
46
 
68
47
  rails g devise_otp:install
69
48
 
70
- 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:
71
50
 
72
51
  rails g devise_otp MODEL
73
52
 
@@ -75,50 +54,48 @@ Don't forget to migrate:
75
54
 
76
55
  rake db:migrate
77
56
 
78
- ### Custom Views
57
+ Add the gem's JavaScript to you `application.js`:
79
58
 
80
- If you want to customise your views (which you likely will want to), you can use the generator:
59
+ //= require devise-otp
81
60
 
82
- rails g devise_otp:views
83
61
 
84
- ### I18n
62
+ ### Custom views
85
63
 
86
- 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:
87
65
 
66
+ rails g devise_otp:views
88
67
 
89
- ## Usage
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.
90
69
 
91
- With this extension enabled, the following is expected behaviour:
70
+ ### I18n
71
+
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_
92
73
 
93
- * 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)
94
- * 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)
95
- * If config.otp_mandatory or model_instance.otp_mandatory, users will be required to enable, and provision, next time they successfully sign-in.
74
+ ### QR codes
96
75
 
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.
97
77
 
98
- ### Configuration Options
78
+ If you need something more, have a look at [QR codes](/docs/QR_CODES.md) documentation file.
99
79
 
100
- The install generator adds some options to the end of your Devise config file (config/initializers/devise.rb)
80
+ ## Configuration
101
81
 
102
- * 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.
103
- * config.otp_authentication_timeout - how long the user has to authenticate with their token. (defaults to 3.minutes)s
104
- * 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. (default: 3)
105
- * config.otp_credentials_refresh - Users that have logged in longer than this time ago, or haven't refreshed, are boing to be asked their password (and an OTP token, if enabled) before they can see or change their otp informations. (defaults to 15.minutes)
106
- * config.recovery_tokens - Whether the users are given a list of one-time recovery tokens, for emergency access (default: true)
107
- * 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)
82
+ The install generator adds some options to the end of your Devise config file (`config/initializers/devise.rb`):
108
83
 
109
- ## 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.
110
92
 
111
- 1. Fork it
112
- 2. Create your feature branch (`git checkout -b my-new-feature`)
113
- 3. Commit your changes (`git commit -am 'Add some feature'`)
114
- 4. Push to the branch (`git push origin my-new-feature`)
115
- 5. Create new Pull Request
93
+ ## Authors
116
94
 
117
- ## 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/).
118
96
 
119
- 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.
120
- 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!
121
98
 
122
99
  ## License
123
100
 
124
- MIT Licensed
101
+ MIT Licensed
data/Rakefile CHANGED
File without changes
@@ -0,0 +1 @@
1
+ //= require_tree .