authentication-zero 2.16.0 → 2.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +0 -7
- data/lib/authentication_zero/version.rb +1 -1
- data/lib/generators/authentication/authentication_generator.rb +6 -3
- data/lib/generators/authentication/templates/controllers/api/identity/email_verifications_controller.rb.tt +2 -3
- data/lib/generators/authentication/templates/controllers/html/application_controller.rb.tt +4 -0
- data/lib/generators/authentication/templates/controllers/html/sessions/sudos_controller.rb.tt +0 -4
- data/lib/generators/authentication/templates/erb/home/index.html.erb.tt +5 -7
- data/lib/generators/authentication/templates/erb/sessions/new.html.erb.tt +1 -2
- data/lib/generators/authentication/templates/models/user.rb.tt +3 -3
- metadata +2 -3
- data/authentication-zero-api.md +0 -192
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa899dd7d78a0c135998ca417f8adb5c412b1f7fb5cc3fb84839d8992dc5dd1c
|
4
|
+
data.tar.gz: af3d846901b8810cb49bb4be027f5c107514bd8f03c4ecda80947ffe5bb4847d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f83cb1e7672a469ac38fade46e2feeb1200366fd6d8b57efdc0f6d871099a3cb18f3bd35421bb721c9c367cc21061fbc79055c8481e2c8c30765123e8b3dfa8
|
7
|
+
data.tar.gz: 4516a0ae989e67eb5d9dc23ec72965107031fa7d6a52f0a0c392225c816b1e9daac3d07168e9be135c84940d684fd393a6d31e191cdffcac8b682b61251187d6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -24,7 +24,6 @@ The purpose of authentication zero is to generate a pre-built authentication sys
|
|
24
24
|
- Manage multiple sessions & devices
|
25
25
|
- Activity log (--trackable)
|
26
26
|
- Log out
|
27
|
-
- [API documentation](https://github.com/lazaronixon/authentication-zero/blob/master/authentication-zero-api.md)
|
28
27
|
|
29
28
|
## Security and best practices
|
30
29
|
|
@@ -40,8 +39,6 @@ The purpose of authentication zero is to generate a pre-built authentication sys
|
|
40
39
|
|
41
40
|
## Installation
|
42
41
|
|
43
|
-
Add this lines to your application's Gemfile:
|
44
|
-
|
45
42
|
```
|
46
43
|
$ bundle add authentication-zero
|
47
44
|
```
|
@@ -52,10 +49,6 @@ $ bundle add authentication-zero
|
|
52
49
|
$ rails generate authentication
|
53
50
|
```
|
54
51
|
|
55
|
-
```
|
56
|
-
$ bundle install
|
57
|
-
```
|
58
|
-
|
59
52
|
## Development
|
60
53
|
|
61
54
|
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
@@ -15,9 +15,12 @@ class AuthenticationGenerator < Rails::Generators::Base
|
|
15
15
|
source_root File.expand_path("templates", __dir__)
|
16
16
|
|
17
17
|
def add_gems
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
gem "bcrypt", "~> 3.1.7", comment: "Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]"
|
19
|
+
|
20
|
+
if redis?
|
21
|
+
gem "redis", ">= 4.0.1", comment: "Use Redis adapter to run additional authentication features"
|
22
|
+
gem "kredis", comment: "Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]"
|
23
|
+
end
|
21
24
|
|
22
25
|
if options.pwned?
|
23
26
|
gem "pwned", comment: "Use Pwned to check if a password has been found in any of the huge data breaches [https://github.com/philnash/pwned]"
|
@@ -4,8 +4,7 @@ class Identity::EmailVerificationsController < ApplicationController
|
|
4
4
|
before_action :set_user, only: :edit
|
5
5
|
|
6
6
|
def edit
|
7
|
-
@user.update!
|
8
|
-
head :no_content
|
7
|
+
@user.update!(verified: true); head(:no_content)
|
9
8
|
end
|
10
9
|
|
11
10
|
def create
|
@@ -27,5 +26,5 @@ class Identity::EmailVerificationsController < ApplicationController
|
|
27
26
|
rescue
|
28
27
|
render json: { error: "That email verification link is invalid" }, status: :bad_request
|
29
28
|
<%- end -%>
|
30
|
-
|
29
|
+
end
|
31
30
|
end
|
@@ -3,7 +3,11 @@ class ApplicationController < ActionController::Base
|
|
3
3
|
before_action :authenticate
|
4
4
|
<%- if options.sudoable? %>
|
5
5
|
def require_sudo
|
6
|
+
<%- if omniauthable? -%>
|
7
|
+
unless Current.session.sudo? || Current.session.user.provider.present?
|
8
|
+
<%- else -%>
|
6
9
|
unless Current.session.sudo?
|
10
|
+
<%- end -%>
|
7
11
|
redirect_to new_sessions_sudo_path(proceed_to_url: request.url)
|
8
12
|
end
|
9
13
|
end
|
data/lib/generators/authentication/templates/controllers/html/sessions/sudos_controller.rb.tt
CHANGED
@@ -5,11 +5,7 @@ class Sessions::SudosController < ApplicationController
|
|
5
5
|
def create
|
6
6
|
session = Current.session
|
7
7
|
|
8
|
-
<%- if omniauthable? -%>
|
9
|
-
if session.user.authenticate(params[:password]) || session.user.provider
|
10
|
-
<%- else -%>
|
11
8
|
if session.user.authenticate(params[:password])
|
12
|
-
<%- end -%>
|
13
9
|
session.sudo.mark; redirect_to(params[:proceed_to_url])
|
14
10
|
else
|
15
11
|
redirect_to new_sessions_sudo_path(proceed_to_url: params[:proceed_to_url]), alert: "The password you entered is incorrect"
|
@@ -14,19 +14,17 @@
|
|
14
14
|
<div>
|
15
15
|
<%%= link_to "Devices & Sessions", sessions_path %>
|
16
16
|
</div>
|
17
|
-
|
18
|
-
<%- if options.trackable? -%>
|
17
|
+
<%- if options.trackable? %>
|
19
18
|
<div>
|
20
|
-
|
19
|
+
<%%= link_to "Activity Log", authentications_events_path %>
|
21
20
|
</div>
|
22
|
-
|
23
21
|
<%- end -%>
|
24
|
-
<%- if two_factor?
|
22
|
+
<%- if two_factor? %>
|
25
23
|
<div>
|
26
|
-
|
24
|
+
<%%= link_to "Two-Factor Authentication", new_two_factor_authentication_totp_path %>
|
27
25
|
</div>
|
28
|
-
|
29
26
|
<%- end -%>
|
27
|
+
|
30
28
|
<br>
|
31
29
|
|
32
30
|
<%%= button_to "Log out", Current.session, method: :delete %>
|
@@ -18,11 +18,11 @@ class User < ApplicationRecord
|
|
18
18
|
validates :password, not_pwned: { message: "might easily be guessed" }
|
19
19
|
<%- end -%>
|
20
20
|
|
21
|
-
before_validation do
|
22
|
-
self.email = email.
|
21
|
+
before_validation if: -> { email.present? } do
|
22
|
+
self.email = email.downcase.strip
|
23
23
|
end
|
24
24
|
|
25
|
-
before_validation if: :email_changed? do
|
25
|
+
before_validation if: :email_changed?, unless: :new_record? do
|
26
26
|
self.verified = false
|
27
27
|
end
|
28
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authentication-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.16.
|
4
|
+
version: 2.16.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nixon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -29,7 +29,6 @@ files:
|
|
29
29
|
- LICENSE.txt
|
30
30
|
- README.md
|
31
31
|
- Rakefile
|
32
|
-
- authentication-zero-api.md
|
33
32
|
- authentication-zero.gemspec
|
34
33
|
- lib/authentication-zero.rb
|
35
34
|
- lib/authentication_zero.rb
|
data/authentication-zero-api.md
DELETED
@@ -1,192 +0,0 @@
|
|
1
|
-
# Authentication Zero API
|
2
|
-
|
3
|
-
This document describe the api endpoints available in authentication-zero.
|
4
|
-
|
5
|
-
## Making a request
|
6
|
-
|
7
|
-
To make a sign in request for example, append sign_in to the base URL to form something like http://localhost:3000/sign_in, also notice you have to include the Content-Type header and the JSON data: In cURL, it looks like this:
|
8
|
-
|
9
|
-
``` shell
|
10
|
-
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
|
11
|
-
-H 'Content-Type: application/json' \
|
12
|
-
-H 'User-Agent: MyApp (yourname@example.com)' \
|
13
|
-
-d '{ "email": "lazaronixon@hotmail.com", "password": "secret", "password_confirmation": "secret" }' \
|
14
|
-
http://localhost:3000/sign_in
|
15
|
-
```
|
16
|
-
|
17
|
-
## API endpoints
|
18
|
-
|
19
|
-
- [Sign up](#sign-up)
|
20
|
-
- [Sign in](#sign-in)
|
21
|
-
- [Get your sessions](#get-your-sessions)
|
22
|
-
- [Get a session](#get-a-session)
|
23
|
-
- [Destroy a session](#destroy-a-session)
|
24
|
-
- [Update your password](#update-your-password)
|
25
|
-
- [Update your email](#update-your-email)
|
26
|
-
- [Send verification email](#send-verification-email)
|
27
|
-
- [Verify email](#verify-email)
|
28
|
-
- [Send password reset email](#send-password-reset-email)
|
29
|
-
- [Reset password](#reset-password)
|
30
|
-
|
31
|
-
## Registrations
|
32
|
-
|
33
|
-
### Sign up
|
34
|
-
|
35
|
-
* `POST /sign_up` creates a user on database.
|
36
|
-
|
37
|
-
###### Example JSON Request
|
38
|
-
|
39
|
-
``` json
|
40
|
-
{
|
41
|
-
"email": "lazaronixon@hotmail.com",
|
42
|
-
"password": "Secret1*2*3*4*5*6",
|
43
|
-
"password_confirmation": "Secret1*2*3*4*5*6"
|
44
|
-
}
|
45
|
-
```
|
46
|
-
|
47
|
-
This endpoint will return `201 Created` with the current JSON representation of the user if the creation was a success.
|
48
|
-
|
49
|
-
## Sessions
|
50
|
-
|
51
|
-
### Sign in
|
52
|
-
|
53
|
-
* `POST /sign_in` creates a session on database.
|
54
|
-
|
55
|
-
###### Example JSON Request
|
56
|
-
|
57
|
-
``` json
|
58
|
-
{
|
59
|
-
"email": "lazaronixon@hotmail.com",
|
60
|
-
"password": "Secret1*2*3*4*5*6"
|
61
|
-
}
|
62
|
-
```
|
63
|
-
|
64
|
-
This endpoint will return `201 Created` with the current JSON representation of the session if the creation was a success, also you will receive a `X-Session-Token` that you will use as your authorization token.
|
65
|
-
|
66
|
-
|
67
|
-
### Get your sessions
|
68
|
-
|
69
|
-
* `GET /sessions` will return a list of sessions.
|
70
|
-
|
71
|
-
###### Example JSON Response
|
72
|
-
|
73
|
-
``` json
|
74
|
-
[
|
75
|
-
{
|
76
|
-
"id": 2,
|
77
|
-
"user_id": 1,
|
78
|
-
"user_agent": "insomnia/2022.1.0",
|
79
|
-
"ip_address": "127.0.0.1",
|
80
|
-
"created_at": "2022-03-04T17:20:33.632Z",
|
81
|
-
"updated_at": "2022-03-04T17:20:33.632Z"
|
82
|
-
},
|
83
|
-
{
|
84
|
-
"id": 1,
|
85
|
-
"user_id": 1,
|
86
|
-
"user_agent": "insomnia/2022.1.0",
|
87
|
-
"ip_address": "127.0.0.1",
|
88
|
-
"created_at": "2022-03-04T17:14:03.386Z",
|
89
|
-
"updated_at": "2022-03-04T17:14:03.386Z"
|
90
|
-
}
|
91
|
-
]
|
92
|
-
```
|
93
|
-
|
94
|
-
### Get a session
|
95
|
-
|
96
|
-
* `GET /sessions/1` will return the session with an ID of 1.
|
97
|
-
|
98
|
-
###### Example JSON Response
|
99
|
-
|
100
|
-
``` json
|
101
|
-
{
|
102
|
-
"id": 1,
|
103
|
-
"user_id": 1,
|
104
|
-
"user_agent": "insomnia/2022.1.0",
|
105
|
-
"ip_address": "127.0.0.1",
|
106
|
-
"created_at": "2022-03-04T17:14:03.386Z",
|
107
|
-
"updated_at": "2022-03-04T17:14:03.386Z"
|
108
|
-
}
|
109
|
-
```
|
110
|
-
|
111
|
-
### Destroy a session
|
112
|
-
|
113
|
-
* `DELETE /sessions/1` will destroy the session with an ID of 1.
|
114
|
-
|
115
|
-
Returns `204 No Content` if successful.
|
116
|
-
|
117
|
-
## Password
|
118
|
-
|
119
|
-
### Update your password
|
120
|
-
|
121
|
-
* `PUT /password` allows changing your password.
|
122
|
-
|
123
|
-
###### Example JSON Request
|
124
|
-
|
125
|
-
``` json
|
126
|
-
{
|
127
|
-
"current_password": "Secret1*2*3*4*5*6",
|
128
|
-
"password": "NewPassword12$34$56$7",
|
129
|
-
"password_confirmation": "NewPassword12$34$56$7"
|
130
|
-
}
|
131
|
-
```
|
132
|
-
|
133
|
-
This endpoint will return 200 OK with the current JSON representation of the user if the update was a success.
|
134
|
-
|
135
|
-
## Email
|
136
|
-
|
137
|
-
### Update your email
|
138
|
-
|
139
|
-
* `PUT /identity/email` allows changing your email. **(requires sudo)**.
|
140
|
-
|
141
|
-
###### Example JSON Request
|
142
|
-
|
143
|
-
``` json
|
144
|
-
{
|
145
|
-
"current_password": "Secret1*2*3*4*5*6",
|
146
|
-
"email": "new_email@hey.com"
|
147
|
-
}
|
148
|
-
```
|
149
|
-
|
150
|
-
This endpoint will return 200 OK with the current JSON representation of the user if the update was a success.
|
151
|
-
|
152
|
-
## Email verification
|
153
|
-
|
154
|
-
### Send verification email
|
155
|
-
|
156
|
-
* `POST /identity/email_verification` sends an email verification with the instructions and link to proceed with the verification.
|
157
|
-
|
158
|
-
Returns `204 No Content` if successful.
|
159
|
-
|
160
|
-
### Verify email
|
161
|
-
|
162
|
-
* `GET /identity/email_verification` verify your email using a temporary token.
|
163
|
-
|
164
|
-
**Required parameters:** `email` and `token`.
|
165
|
-
|
166
|
-
Example: `/identity/email_verification?email=lazaronixon@hotmail.com&token=eyJfcmFpbHMiOnsibWVzc2FnZSI6Ik1nPT0iLCJleHAiOm51bGwsInB1ciI6InNlc3Npb24ifX0=--1a277b4a5576c6e371144a22476979a18d3e45fb8515a79e815cd4b95eb5fb6b`
|
167
|
-
|
168
|
-
Returns `204 No Content` if successful.
|
169
|
-
|
170
|
-
## Password reset
|
171
|
-
|
172
|
-
### Send password reset email
|
173
|
-
|
174
|
-
* `POST /identity/password_reset` sends a password reset email with the instructions and link to proceed reset.
|
175
|
-
|
176
|
-
Returns `204 No Content` if successful.
|
177
|
-
|
178
|
-
### Reset password
|
179
|
-
|
180
|
-
* `PUT /identity/password_reset` allows changing your password through a email token.
|
181
|
-
|
182
|
-
##### Example JSON Request
|
183
|
-
|
184
|
-
``` json
|
185
|
-
{
|
186
|
-
"password": "NewPassword12$34$56$7",
|
187
|
-
"password_confirmation": "NewPassword12$34$56$7",
|
188
|
-
"token": "eyJfcmFpbHMiOnsibWVzc2FnZSI6Ik1nPT0iLCJleHAiOm51bGwsInB1ciI6InNlc3Npb24ifX0=--1a277b4a5576c6e371144a22476979a18d3e45fb8515a79e815cd4b95eb5fb6b",
|
189
|
-
}
|
190
|
-
```
|
191
|
-
|
192
|
-
This endpoint will return 200 OK with the current JSON representation of the user if the update was a success.
|