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.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +36 -0
- data/.gitignore +0 -0
- data/Gemfile +1 -22
- data/LICENSE.txt +0 -0
- data/README.md +43 -66
- data/Rakefile +0 -0
- data/app/assets/javascripts/devise-otp.js +1 -0
- data/app/assets/javascripts/qrcode.js +609 -0
- data/app/controllers/devise_otp/devise/credentials_controller.rb +102 -0
- data/app/controllers/devise_otp/devise/tokens_controller.rb +112 -0
- data/app/views/devise/credentials/refresh.html.erb +19 -0
- data/app/views/devise/credentials/show.html.erb +31 -0
- data/app/views/devise/tokens/_token_secret.html.erb +23 -0
- data/app/views/devise/tokens/_trusted_devices.html.erb +12 -0
- data/app/views/devise/tokens/recovery.html.erb +21 -0
- data/app/views/devise/tokens/recovery_codes.text.erb +3 -0
- data/app/views/devise/tokens/show.html.erb +21 -0
- data/config/locales/en.yml +10 -10
- data/devise-otp.gemspec +14 -9
- data/docs/QR_CODES.md +48 -0
- data/lib/devise-otp/version.rb +1 -1
- data/lib/devise-otp.rb +22 -14
- data/lib/devise_otp_authenticatable/controllers/helpers.rb +29 -16
- data/lib/devise_otp_authenticatable/controllers/url_helpers.rb +6 -9
- data/lib/devise_otp_authenticatable/engine.rb +22 -13
- data/lib/devise_otp_authenticatable/hooks/sessions.rb +8 -7
- data/lib/devise_otp_authenticatable/hooks.rb +1 -1
- data/lib/devise_otp_authenticatable/models/otp_authenticatable.rb +28 -28
- data/lib/devise_otp_authenticatable/routes.rb +9 -10
- data/lib/generators/active_record/devise_otp_generator.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +1 -2
- data/lib/generators/devise_otp/devise_otp_generator.rb +0 -0
- data/lib/generators/devise_otp/install_generator.rb +30 -5
- data/lib/generators/devise_otp/views_generator.rb +2 -3
- data/test/dummy/README.rdoc +0 -0
- data/test/dummy/Rakefile +0 -0
- data/test/dummy/app/assets/config/manifest.js +2 -0
- data/test/dummy/app/assets/javascripts/application.js +1 -0
- data/test/dummy/app/assets/stylesheets/application.css +0 -0
- data/test/dummy/app/controllers/application_controller.rb +1 -1
- data/test/dummy/app/controllers/posts_controller.rb +2 -0
- data/test/dummy/app/helpers/application_helper.rb +0 -0
- data/test/dummy/app/helpers/posts_helper.rb +0 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/post.rb +0 -0
- data/test/dummy/app/models/user.rb +1 -1
- data/test/dummy/app/views/layouts/application.html.erb +0 -0
- data/test/dummy/app/views/posts/_form.html.erb +0 -0
- data/test/dummy/app/views/posts/edit.html.erb +0 -0
- data/test/dummy/app/views/posts/index.html.erb +0 -0
- data/test/dummy/app/views/posts/new.html.erb +0 -0
- data/test/dummy/app/views/posts/show.html.erb +0 -0
- data/test/dummy/config/application.rb +2 -1
- data/test/dummy/config/boot.rb +0 -0
- data/test/dummy/config/database.yml +1 -1
- data/test/dummy/config/environment.rb +0 -0
- data/test/dummy/config/environments/development.rb +0 -7
- data/test/dummy/config/environments/production.rb +0 -4
- data/test/dummy/config/environments/test.rb +0 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/test/dummy/config/initializers/devise.rb +0 -0
- data/test/dummy/config/initializers/inflections.rb +0 -0
- data/test/dummy/config/initializers/mime_types.rb +0 -0
- data/test/dummy/config/initializers/secret_token.rb +0 -0
- data/test/dummy/config/initializers/session_store.rb +0 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/test/dummy/config/locales/en.yml +0 -0
- data/test/dummy/config/routes.rb +0 -0
- data/test/dummy/config.ru +0 -0
- data/test/dummy/db/migrate/20130125101430_create_users.rb +1 -1
- data/test/dummy/db/migrate/20130131092406_add_devise_to_users.rb +1 -1
- data/test/dummy/db/migrate/20130131142320_create_posts.rb +1 -1
- data/test/dummy/db/migrate/20130131160351_devise_otp_add_to_users.rb +2 -2
- data/test/dummy/db/test.sqlite3-journal +0 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -0
- data/test/dummy/public/422.html +0 -0
- data/test/dummy/public/500.html +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/persistence_test.rb +81 -0
- data/test/integration/refresh_test.rb +2 -18
- data/test/integration/sign_in_test.rb +14 -4
- data/test/integration/token_test.rb +31 -0
- data/test/integration_tests_helper.rb +19 -2
- data/test/model_tests_helper.rb +0 -0
- data/test/models/otp_authenticatable_test.rb +14 -9
- data/test/orm/active_record.rb +3 -1
- data/test/test_helper.rb +71 -2
- metadata +135 -24
- data/.travis.yml +0 -11
- data/app/controllers/devise_otp/credentials_controller.rb +0 -106
- data/app/controllers/devise_otp/tokens_controller.rb +0 -105
- data/app/views/devise_otp/credentials/refresh.html.erb +0 -20
- data/app/views/devise_otp/credentials/show.html.erb +0 -23
- data/app/views/devise_otp/tokens/_token_secret.html.erb +0 -17
- data/app/views/devise_otp/tokens/recovery.html.erb +0 -21
- data/app/views/devise_otp/tokens/show.html.erb +0 -31
- data/lib/devise_otp_authenticatable/mapping.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6b5132454cb31efb85ab78d8a0866c6e98e3e3fc8f9c51fa770b735e59a0d976
|
4
|
+
data.tar.gz: ef69e79487527616462f0c3c918094a9338ede9b59a8aef005b34549ae231166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
5
|
+
It has the following features:
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
- Optional and mandatory OTP enforcement
|
8
|
+
- Setting up trusted browsers for limited access
|
9
|
+
- Generating QR codes
|
12
10
|
|
13
|
-
|
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
|
-
|
16
|
+
Device OTP was recently updated to work with Rails 7 and Turbo.
|
19
17
|
|
20
|
-
|
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
|
-
|
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
|
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
|
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
|
-
|
57
|
+
Add the gem's JavaScript to you `application.js`:
|
79
58
|
|
80
|
-
|
59
|
+
//= require devise-otp
|
81
60
|
|
82
|
-
rails g devise_otp:views
|
83
61
|
|
84
|
-
###
|
62
|
+
### Custom views
|
85
63
|
|
86
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
78
|
+
If you need something more, have a look at [QR codes](/docs/QR_CODES.md) documentation file.
|
99
79
|
|
100
|
-
|
80
|
+
## Configuration
|
101
81
|
|
102
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 .
|