rails_auth_generator 0.1.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/README.md +129 -23
- data/README_NEW.md +0 -59
- data/lib/generators/auth/auth_generator.rb +70 -53
- data/lib/generators/auth/templates/auth_controller.rb +66 -9
- data/lib/generators/auth/templates/migrations/create_refresh_token.rb +14 -0
- data/lib/generators/auth/templates/refresh_token.rb +9 -0
- data/lib/generators/auth/templates/user.rb +19 -1
- data/lib/generators/auth/templates/users_controller.rb +1 -1
- data/lib/rails_auth_generator/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57cf671f5c6352bcd54a7a4766bc3ae0dc0a515d2eca9df4508f59e2da941dde
|
4
|
+
data.tar.gz: e67935ab3b0c63a1765a4411818d5d945ae8ac6ad9d22f6e32f9af895d7c54ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 260738a21ff80dc301f384c446539bb9a98fd882f38db0a000fb46fd7dacba7202f61dc2f7c4ebaf9860b7414b501e2578fbfc825676d003d960fdd9466101d5
|
7
|
+
data.tar.gz: 4b3fc7f835b388f967edcbba74a6ee558a007dfd4ae6fedfea59600bd0885b4175f6b59ab5c2f2ff2e49ad8cd0bd6e0fcbc18b37caafe235be054f9227285a22
|
data/README.md
CHANGED
@@ -1,43 +1,149 @@
|
|
1
1
|
# RailsAuthGenerator
|
2
2
|
|
3
|
-
|
3
|
+
**RailsAuthGenerator** is a Rails generator that scaffolds a **JWT-based authentication system** with user management, password resets, refresh token rotation, and secure cookie handling. It saves you weeks of setup by providing all the models, controllers, serializers, and mailers you need for a robust, production-ready authentication flow.
|
4
4
|
|
5
|
-
|
5
|
+
---
|
6
6
|
|
7
|
-
##
|
7
|
+
## ✨ Features
|
8
8
|
|
9
|
-
|
9
|
+
- 🔑 **JWT Authentication**
|
10
|
+
- Access tokens (short-lived, default 15 min)
|
11
|
+
- Refresh tokens (stored securely in HttpOnly cookies)
|
12
|
+
- Token rotation + reuse detection
|
13
|
+
- Logout everywhere
|
14
|
+
- 👤 **User management**
|
15
|
+
- User model with secure password
|
16
|
+
- Role support (admin, user)
|
17
|
+
- ✉️ **Password reset**
|
18
|
+
- Password reset tokens sent via email
|
19
|
+
- 🛠️ **Rails Generators**
|
20
|
+
- User model + migrations
|
21
|
+
- Auth controllers (`auth`, `users`, `password_resets`)
|
22
|
+
- Serializers and mailers
|
23
|
+
- ⚡ Works with **Rails 6.0+**
|
10
24
|
|
11
|
-
|
25
|
+
---
|
12
26
|
|
13
|
-
|
14
|
-
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
15
|
-
```
|
27
|
+
## 📦 Installation
|
16
28
|
|
17
|
-
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
`gem 'rails_auth_generator', '~> 0.1.0'`
|
18
31
|
|
19
|
-
|
20
|
-
|
21
|
-
```
|
32
|
+
and then run:
|
33
|
+
`bundle install`
|
22
34
|
|
23
|
-
|
35
|
+
Or install it manually:
|
36
|
+
`gem install rails_auth_generator`
|
24
37
|
|
25
|
-
|
38
|
+
If you want the latest version from GitHub:
|
39
|
+
`gem 'rails_auth_generator', git: 'https://github.com/Zeyad-Hassan-1/authJWT.git'`
|
26
40
|
|
27
|
-
|
41
|
+
---
|
28
42
|
|
29
|
-
|
43
|
+
## 🚀 Usage
|
30
44
|
|
31
|
-
|
45
|
+
Generate the full authentication system:
|
46
|
+
`rails generate auth`
|
32
47
|
|
33
|
-
|
48
|
+
Then run:
|
49
|
+
`bundle install`
|
50
|
+
`rails db:migrate`
|
34
51
|
|
35
|
-
|
52
|
+
This scaffolds:
|
53
|
+
- User model & migrations
|
54
|
+
- Controllers for authentication, users, and password resets
|
55
|
+
- Mailers for password reset
|
56
|
+
- Serializers for user data
|
36
57
|
|
37
|
-
|
58
|
+
You can freely customize the generated files to match your app’s requirements.
|
38
59
|
|
39
|
-
|
60
|
+
---
|
40
61
|
|
41
|
-
##
|
62
|
+
## 🔧 Additional Setup
|
42
63
|
|
43
|
-
|
64
|
+
### 1. Enable CORS
|
65
|
+
Uncomment the CORS config in `config/initializers/cors.rb` if building an API:
|
66
|
+
|
67
|
+
`Rails.application.config.middleware.insert_before 0, Rack::Cors do
|
68
|
+
allow do
|
69
|
+
origins '*'
|
70
|
+
resource '*',
|
71
|
+
headers: :any,
|
72
|
+
methods: [:get, :post, :put, :patch, :delete, :options, :head],
|
73
|
+
credentials: true
|
74
|
+
end
|
75
|
+
end`
|
76
|
+
|
77
|
+
### 2. Set JWT Secret
|
78
|
+
Edit your Rails credentials:
|
79
|
+
`VISUAL="code --wait" bin/rails credentials:edit`
|
80
|
+
|
81
|
+
Add:
|
82
|
+
|
83
|
+
`jwt:
|
84
|
+
secret: <your_generated_secret>`
|
85
|
+
|
86
|
+
Generate a secret key:
|
87
|
+
`rails secret`
|
88
|
+
|
89
|
+
Replace `<your_generated_secret>` with the generated key.
|
90
|
+
|
91
|
+
---
|
92
|
+
|
93
|
+
## 📚 API Overview
|
94
|
+
|
95
|
+
| Route | Method | Description |
|
96
|
+
|-------------------|--------|-------------|
|
97
|
+
| `/signup` | POST | Create a new user |
|
98
|
+
| `/login` | POST | Authenticate user, return JWT + set refresh cookie |
|
99
|
+
| `/me` | GET | Get current logged-in user |
|
100
|
+
| `/refresh` | POST | Rotate refresh token + issue new JWT |
|
101
|
+
| `/logout` | DELETE | Revoke refresh token + clear cookie |
|
102
|
+
| `/password_resets`| POST | Request a password reset |
|
103
|
+
| `/password_resets` | PUT | Reset password with token |
|
104
|
+
|
105
|
+
---
|
106
|
+
|
107
|
+
## 🧪 Example Usage
|
108
|
+
|
109
|
+
1. Sign up:
|
110
|
+
`curl -X POST http://localhost:3000/signup -H "Content-Type: application/json" -d '{"user": {"email":"test@example.com","password":"secret123"}}'`
|
111
|
+
|
112
|
+
2. Login:
|
113
|
+
`curl -X POST http://localhost:3000/login -H "Content-Type: application/json" -d '{"email":"test@example.com","password":"secret123"}'`
|
114
|
+
➡️ Returns `{ "token": "...", "user": {...} }`
|
115
|
+
Refresh token is stored in an **HttpOnly cookie**.
|
116
|
+
|
117
|
+
3. Access protected route:
|
118
|
+
`curl -H "Authorization: Bearer <your_token>" http://localhost:3000/me`
|
119
|
+
|
120
|
+
4. Refresh token:
|
121
|
+
`curl -X POST http://localhost:3000/refresh`
|
122
|
+
➡️ Returns new access token, rotates refresh cookie.
|
123
|
+
|
124
|
+
5. Logout:
|
125
|
+
`curl -X DELETE http://localhost:3000/logout`
|
126
|
+
➡️ Revokes refresh token + clears cookie.
|
127
|
+
|
128
|
+
---
|
129
|
+
|
130
|
+
## 🛡️ Security Defaults
|
131
|
+
|
132
|
+
- Access tokens expire after **15 minutes**
|
133
|
+
- Refresh tokens expire after **7 days**
|
134
|
+
- Refresh tokens are **rotated on every use**
|
135
|
+
- Reused tokens trigger **global logout**
|
136
|
+
|
137
|
+
---
|
138
|
+
|
139
|
+
## 🤝 Contributing
|
140
|
+
|
141
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/Zeyad-Hassan-1/authJWT](https://github.com/Zeyad-Hassan-1/authJWT).
|
142
|
+
|
143
|
+
This project follows a [Code of Conduct](CODE_OF_CONDUCT.md). Please respect it in all interactions.
|
144
|
+
|
145
|
+
---
|
146
|
+
|
147
|
+
## 📄 License
|
148
|
+
|
149
|
+
This gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
data/README_NEW.md
CHANGED
@@ -1,59 +0,0 @@
|
|
1
|
-
# RailsAuthGenerator
|
2
|
-
|
3
|
-
RailsAuthGenerator provides Rails generators for authentication, user management, password resets, and mailers, streamlining the setup of secure user authentication in Rails applications. It helps you quickly scaffold all necessary models, controllers, mailers, and migrations for a robust authentication system.
|
4
|
-
|
5
|
-
## Features
|
6
|
-
|
7
|
-
- User model and migration generator
|
8
|
-
- Authentication controller and password reset controller
|
9
|
-
- User serializer for API responses
|
10
|
-
- Mailers for sending token to reset password
|
11
|
-
- Easy integration with Rails 6.0+
|
12
|
-
|
13
|
-
## Installation
|
14
|
-
|
15
|
-
Add this line to your application's Gemfile:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
bundle add rails_auth_generator
|
19
|
-
```
|
20
|
-
|
21
|
-
Or install it manually:
|
22
|
-
|
23
|
-
```bash
|
24
|
-
gem install rails_auth_generator
|
25
|
-
```
|
26
|
-
|
27
|
-
If you want to use the latest version from GitHub:
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
gem 'rails_auth_generator', git: 'https://github.com/Zeyad-Hassan-1/authJWT.git'
|
31
|
-
```
|
32
|
-
|
33
|
-
## Usage
|
34
|
-
|
35
|
-
Run the generator to scaffold authentication features:
|
36
|
-
|
37
|
-
```bash
|
38
|
-
rails generate auth
|
39
|
-
```
|
40
|
-
|
41
|
-
This will create:
|
42
|
-
- User model and migration
|
43
|
-
- Authentication controllers (auth, password resets, users)
|
44
|
-
- Mailers for sending token to reset password
|
45
|
-
- Serializers for user data
|
46
|
-
|
47
|
-
You can customize the generated files as needed for your application.
|
48
|
-
|
49
|
-
## Contributing
|
50
|
-
|
51
|
-
Bug reports and pull requests are welcome on GitHub at [https://github.com/Zeyad-Hassan-1/authJWT](https://github.com/Zeyad-Hassan-1/authJWT). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
|
52
|
-
|
53
|
-
## License
|
54
|
-
|
55
|
-
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
56
|
-
|
57
|
-
## Code of Conduct
|
58
|
-
|
59
|
-
Everyone interacting in the RailsAuthGenerator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
@@ -2,31 +2,41 @@ class AuthGenerator < Rails::Generators::Base
|
|
2
2
|
include Rails::Generators::Migration
|
3
3
|
source_root File.expand_path("templates", __dir__)
|
4
4
|
|
5
|
-
|
6
|
-
insert_into_file "Gemfile", after: /^source ['"].*['"]\n/ do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
def modify_gemfile
|
6
|
+
insert_into_file "Gemfile", after: /^source ['"].*['"]\n/ do
|
7
|
+
<<~RUBY
|
8
|
+
gem 'bcrypt', '~> 3.1', '>= 3.1.12'
|
9
|
+
gem 'jwt', '~> 2.5'
|
10
|
+
gem 'rack-cors'
|
11
|
+
gem 'active_model_serializers', '~> 0.10.12'
|
12
|
+
RUBY
|
13
|
+
end
|
13
14
|
end
|
14
15
|
|
16
|
+
def modify_application_rb
|
17
|
+
insert_into_file "config/application.rb", after: "config.api_only = true" do
|
18
|
+
<<~RUBY
|
19
|
+
config.middleware.use ActionDispatch::Cookies
|
20
|
+
RUBY
|
15
21
|
end
|
16
22
|
|
23
|
+
end
|
24
|
+
|
17
25
|
def add_routes
|
18
26
|
route <<~RUBY
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
# config/routes.rb
|
28
|
+
post '/login', to: 'auth#login'
|
29
|
+
post '/refresh', to: 'auth#refresh'
|
30
|
+
post '/logout', to: 'auth#logout'
|
31
|
+
post '/signup', to: 'users#create'
|
32
|
+
get '/me', to: 'users#me'
|
33
|
+
resources :password_resets, only: [:create] do
|
34
|
+
collection do
|
35
|
+
put '/', to: 'password_resets#update' # PUT /password_resets
|
36
|
+
end
|
26
37
|
end
|
27
|
-
|
28
|
-
|
29
|
-
post '/users/:id/make_admin', to: 'users#make_admin'
|
38
|
+
# Admin routes
|
39
|
+
post '/users/:id/make_admin', to: 'users#make_admin'
|
30
40
|
RUBY
|
31
41
|
end
|
32
42
|
|
@@ -36,6 +46,7 @@ end
|
|
36
46
|
template "users_controller.rb", "app/controllers/users_controller.rb"
|
37
47
|
template "password_resets_controller.rb", "app/controllers/password_resets_controller.rb"
|
38
48
|
template "user.rb", "app/models/user.rb"
|
49
|
+
template "refresh_token.rb", "app/models/refresh_token.rb"
|
39
50
|
template "mailers/user_mailer.rb", "app/mailers/user_mailer.rb"
|
40
51
|
template "mailers/application_mailer.rb", "app/mailers/application_mailer.rb"
|
41
52
|
end
|
@@ -43,58 +54,64 @@ end
|
|
43
54
|
def modify_application_controller
|
44
55
|
inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
|
45
56
|
<<~RUBY
|
46
|
-
|
57
|
+
include ActionController::Cookies
|
58
|
+
before_action :authorized
|
59
|
+
SECRET_KEY = Rails.application.credentials.dig(:jwt, :secret)
|
47
60
|
|
48
|
-
def encode_token(payload)
|
49
|
-
# Add admin status to the payload if user is admin
|
50
|
-
payload[:admin] = @user.admin? if @user.is_a?(User)
|
51
|
-
JWT.encode(payload, 'hellomars1211')
|
52
|
-
end
|
53
61
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
rescue JWT::DecodeError
|
61
|
-
nil
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
62
|
+
def encode_token(payload, exp = 15.minutes.from_now)
|
63
|
+
# Add admin status to the payload if user is admin
|
64
|
+
payload[:admin] = @user.admin? if @user.is_a?(User)
|
65
|
+
payload[:exp] = exp.to_i
|
66
|
+
JWT.encode(payload, SECRET_KEY)
|
67
|
+
end
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
def decoded_token
|
70
|
+
header = request.headers['Authorization']
|
71
|
+
if header
|
72
|
+
token = header.split(" ")[1]
|
73
|
+
begin
|
74
|
+
JWT.decode(token, SECRET_KEY, true, algorithm: 'HS256')
|
75
|
+
rescue JWT::DecodeError
|
76
|
+
nil
|
70
77
|
end
|
71
78
|
end
|
79
|
+
end
|
72
80
|
|
73
|
-
|
74
|
-
|
81
|
+
def current_user
|
82
|
+
if decoded_token
|
83
|
+
user_id = decoded_token[0]['user_id']
|
84
|
+
@user = User.find_by(id: user_id)
|
75
85
|
end
|
86
|
+
end
|
76
87
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
88
|
+
def current_admin
|
89
|
+
current_user && (current_user.admin? || decoded_token[0]['admin'])
|
90
|
+
end
|
82
91
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
92
|
+
def authorized
|
93
|
+
unless !!current_user
|
94
|
+
render json: { message: 'Please log in' }, status: :unauthorized
|
87
95
|
end
|
96
|
+
end
|
88
97
|
|
98
|
+
def admin_authorized
|
99
|
+
unless current_admin
|
100
|
+
render json: { message: 'Admin access required' }, status: :forbidden
|
101
|
+
end
|
102
|
+
end
|
89
103
|
RUBY
|
90
104
|
end
|
91
105
|
end
|
92
106
|
|
93
|
-
|
94
|
-
|
95
|
-
|
107
|
+
def self.next_migration_number(dirname)
|
108
|
+
@prev_migration_nr ||= Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
109
|
+
@prev_migration_nr += 1
|
110
|
+
@prev_migration_nr.to_s
|
111
|
+
end
|
96
112
|
|
97
113
|
def copy_migration
|
98
114
|
migration_template "migrations/create_user.rb", "db/migrate/create_users.rb"
|
115
|
+
migration_template "migrations/create_refresh_token.rb", "db/migrate/create_refresh_tokens.rb"
|
99
116
|
end
|
100
117
|
end
|
@@ -1,22 +1,78 @@
|
|
1
|
+
require "digest"
|
2
|
+
|
1
3
|
class AuthController < ApplicationController
|
2
|
-
skip_before_action :authorized, only: [:login]
|
4
|
+
skip_before_action :authorized, only: [:login, :refresh, :logout]
|
3
5
|
rescue_from ActiveRecord::RecordNotFound, with: :handle_record_not_found
|
4
6
|
|
5
|
-
def login
|
6
|
-
|
7
|
-
if
|
8
|
-
|
7
|
+
def login
|
8
|
+
user = User.find_by!(username: params[:username])
|
9
|
+
if user.authenticate(params[:password])
|
10
|
+
access_token = encode_token({ user_id: user.id }, 15.minutes.from_now)
|
11
|
+
refresh_raw = user.generate_refresh_token
|
12
|
+
|
13
|
+
set_refresh_cookie(refresh_raw, 7.days.from_now)
|
14
|
+
|
9
15
|
render json: {
|
10
|
-
user: UserSerializer.new(
|
11
|
-
|
12
|
-
|
16
|
+
user: UserSerializer.new(user),
|
17
|
+
access_token: access_token
|
18
|
+
# (we're NOT returning refresh in JSON for security)
|
19
|
+
}, status: :ok
|
13
20
|
else
|
14
|
-
render json: {
|
21
|
+
render json: { error: "Invalid credentials" }, status: :unauthorized
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def refresh
|
26
|
+
raw = cookies.encrypted[:refresh_token] || params[:refresh_token]
|
27
|
+
return render json: { error: "missing refresh token" }, status: :unauthorized if raw.blank?
|
28
|
+
|
29
|
+
digest = Digest::SHA256.hexdigest(raw)
|
30
|
+
rt = RefreshToken.find_by(token_digest: digest)
|
31
|
+
|
32
|
+
if rt.nil? || rt.revoked_at.present? || rt.expires_at.past?
|
33
|
+
rt&.user&.revoke_all_refresh_tokens!
|
34
|
+
cookies.delete(:refresh_token)
|
35
|
+
return render json: { error: "Invalid or reused refresh token. Logged out everywhere." }, status: :unauthorized
|
36
|
+
end
|
37
|
+
|
38
|
+
# Issue new access + refresh token
|
39
|
+
new_access_token = encode_token({ user_id: rt.user_id }, 15.minutes.from_now)
|
40
|
+
new_refresh_token = rt.user.generate_refresh_token
|
41
|
+
|
42
|
+
# revoke the old token
|
43
|
+
rt.update!(revoked_at: Time.current)
|
44
|
+
|
45
|
+
# 🔑 store new refresh token in HttpOnly cookie
|
46
|
+
set_refresh_cookie(new_refresh_token, 7.days.from_now)
|
47
|
+
|
48
|
+
render json: { access_token: new_access_token }, status: :ok
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
def logout
|
54
|
+
raw = cookies.encrypted[:refresh_token] || params[:refresh_token]
|
55
|
+
if raw.present?
|
56
|
+
digest = Digest::SHA256.hexdigest(raw)
|
57
|
+
RefreshToken.find_by(token_digest: digest)&.destroy
|
58
|
+
cookies.delete(:refresh_token)
|
15
59
|
end
|
60
|
+
render json: { message: "Logged out" }, status: :ok
|
16
61
|
end
|
17
62
|
|
63
|
+
|
18
64
|
private
|
19
65
|
|
66
|
+
def set_refresh_cookie(raw_token, expires_at)
|
67
|
+
cookies.encrypted[:refresh_token] = {
|
68
|
+
value: raw_token,
|
69
|
+
httponly: true,
|
70
|
+
secure: Rails.env.production?,
|
71
|
+
same_site: :lax,
|
72
|
+
expires: expires_at
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
20
76
|
def login_params
|
21
77
|
params.permit(:username, :password)
|
22
78
|
end
|
@@ -24,4 +80,5 @@ class AuthController < ApplicationController
|
|
24
80
|
def handle_record_not_found(e)
|
25
81
|
render json: { message: "User doesn't exist" }, status: :unauthorized
|
26
82
|
end
|
83
|
+
|
27
84
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateRefreshTokens < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :refresh_tokens do |t|
|
4
|
+
t.references :user, null: false, foreign_key: true
|
5
|
+
t.string :token_digest, null: false
|
6
|
+
t.datetime :expires_at, null: false
|
7
|
+
t.datetime :revoked_at
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :refresh_tokens, :token_digest, unique: true
|
13
|
+
end
|
14
|
+
end
|
@@ -1,7 +1,25 @@
|
|
1
|
+
require "digest"
|
2
|
+
|
1
3
|
class User < ApplicationRecord
|
2
4
|
has_secure_password
|
5
|
+
has_many :refresh_tokens, dependent: :destroy
|
3
6
|
validates :username, uniqueness: true
|
4
|
-
|
7
|
+
|
8
|
+
# returns the RAW token (client uses this), stores only SHA256 digest
|
9
|
+
def generate_refresh_token
|
10
|
+
raw = SecureRandom.hex(64)
|
11
|
+
digest = Digest::SHA256.hexdigest(raw)
|
12
|
+
refresh_tokens.create!(
|
13
|
+
token_digest: digest,
|
14
|
+
expires_at: 7.days.from_now
|
15
|
+
)
|
16
|
+
raw
|
17
|
+
end
|
18
|
+
|
19
|
+
# revoke all tokens for this user
|
20
|
+
def revoke_all_refresh_tokens!
|
21
|
+
refresh_tokens.update_all(revoked_at: Time.current)
|
22
|
+
end
|
5
23
|
|
6
24
|
def generate_password_reset_token!
|
7
25
|
self.reset_token = SecureRandom.urlsafe_base64
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_auth_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeyad Hassan
|
@@ -49,8 +49,10 @@ files:
|
|
49
49
|
- lib/generators/auth/templates/auth_controller.rb
|
50
50
|
- lib/generators/auth/templates/mailers/application_mailer.rb
|
51
51
|
- lib/generators/auth/templates/mailers/user_mailer.rb
|
52
|
+
- lib/generators/auth/templates/migrations/create_refresh_token.rb
|
52
53
|
- lib/generators/auth/templates/migrations/create_user.rb
|
53
54
|
- lib/generators/auth/templates/password_resets_controller.rb
|
55
|
+
- lib/generators/auth/templates/refresh_token.rb
|
54
56
|
- lib/generators/auth/templates/user.rb
|
55
57
|
- lib/generators/auth/templates/user_serializer.rb
|
56
58
|
- lib/generators/auth/templates/users_controller.rb
|