Skip to content

Commit 0c06558

Browse files
committed
Automatically add argon2 and JWT gems to Gemfile
1 parent 63fb437 commit 0c06558

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,15 @@ $ rails generate rodauth:install users
9090
If you want Rodauth endpoints to be exposed via [JSON API]:
9191

9292
```sh
93-
$ rails generate rodauth:install --json # regular authentication using the Rails session
93+
$ rails generate rodauth:install --json # cookied-based authentication
9494
# or
95-
$ rails generate rodauth:install --jwt # token authentication via the "Authorization" header
96-
$ bundle add jwt
95+
$ rails generate rodauth:install --jwt # token-based authentication
9796
```
9897

9998
To use Argon2 instead of bcrypt for password hashing:
10099

101100
```sh
102101
$ rails generate rodauth:install --argon2
103-
$ bundle add argon2
104102
```
105103

106104
## Usage

lib/generators/rodauth/install_generator.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ def add_gems
4343
gem "sequel-activerecord_connection", "~> 2.0", comment: "Enables Sequel to use Active Record's database connection"
4444
gem "after_commit_everywhere", "~> 1.1", comment: "Required for Sequel's transaction hooks to work in all cases (on Active Record < 7.2)" if ActiveRecord.version < Gem::Version.new("7.2")
4545
end
46-
unless argon2?
46+
if argon2?
47+
gem "argon2", "~> 2.3", comment: "Used by Rodauth for password hashing"
48+
else
4749
gem "bcrypt", "~> 3.1", comment: "Used by Rodauth for password hashing"
4850
end
51+
if jwt?
52+
gem "jwt", "~> 2.9", comment: "Used by Rodauth for JWT support"
53+
end
4954
gem "tilt", "~> 2.4", comment: "Used by Rodauth for rendering built-in view and email templates"
5055
end
5156

test/generators/install_generator_test.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class InstallGeneratorTest < Rails::Generators::TestCase
4242
end
4343
assert_file "app/misc/rodauth_main.rb", /convert_token_id_to_integer\? { Account.columns_hash\["id"\]\.type == :integer }/
4444

45-
assert_file "Gemfile", /gem "sequel-activerecord_connection", "~> 2.0"/
46-
assert_file "Gemfile", /gem "after_commit_everywhere", "~> 1.1"/ if ActiveRecord.version < Gem::Version.new("7.2")
45+
assert_file "Gemfile", /gem "sequel-activerecord_connection"/
46+
assert_file "Gemfile", /gem "after_commit_everywhere"/ if ActiveRecord.version < Gem::Version.new("7.2")
4747
end
4848

4949
test "app" do
@@ -62,8 +62,8 @@ class InstallGeneratorTest < Rails::Generators::TestCase
6262
assert_file "app/misc/rodauth_main.rb", /logout_redirect/
6363
assert_file "app/misc/rodauth_main.rb", /# accounts_table :users/
6464

65-
assert_file "Gemfile", /gem "bcrypt", "~> 3.1"/
66-
assert_file "Gemfile", /gem "tilt", "~> 2.4"/
65+
assert_file "Gemfile", /gem "bcrypt"/
66+
assert_file "Gemfile", /gem "tilt"/
6767
end
6868

6969
test "app with --json option" do
@@ -78,6 +78,8 @@ class InstallGeneratorTest < Rails::Generators::TestCase
7878

7979
assert_file "app/misc/rodauth_main.rb", /:login, :logout, :jwt,$/
8080
assert_file "app/misc/rodauth_main.rb", /jwt_secret /
81+
82+
assert_file "Gemfile", /gem "jwt"/
8183
end
8284

8385
test "app with --argon2 option" do
@@ -87,6 +89,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
8789
assert_file "app/misc/rodauth_main.rb", /argon2_secret/
8890

8991
assert_file "Gemfile" do |content|
92+
assert_includes content, "argon2"
9093
refute_includes content, "bcrypt"
9194
end
9295
end

0 commit comments

Comments
 (0)