simple_jwt_auth 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -8
- data/app/assets/config/simple_jwt_auth_manifest.js +0 -1
- data/app/assets/stylesheets/{simple_jwt_auth/sessions.css → sessions.css} +0 -0
- data/app/assets/stylesheets/{simple_jwt_auth/users.css → users.css} +0 -0
- data/app/controllers/sessions_controller.rb +26 -0
- data/app/controllers/users_controller.rb +17 -0
- data/app/helpers/sessions_helper.rb +2 -0
- data/app/helpers/users_helper.rb +2 -0
- data/app/models/user.rb +4 -0
- data/config/routes.rb +5 -3
- data/db/migrate/{20191222061616_create_simple_jwt_auth_users.rb → 20191225083243_create_users.rb} +2 -2
- data/lib/simple_jwt_auth/engine.rb +1 -2
- data/lib/simple_jwt_auth/version.rb +1 -1
- data/lib/tasks/simple_jwt_auth_tasks.rake +4 -7
- metadata +10 -16
- data/app/assets/stylesheets/simple_jwt_auth/application.css +0 -15
- data/app/controllers/simple_jwt_auth/application_controller.rb +0 -5
- data/app/controllers/simple_jwt_auth/sessions_controller.rb +0 -29
- data/app/controllers/simple_jwt_auth/users_controller.rb +0 -22
- data/app/helpers/simple_jwt_auth/sessions_helper.rb +0 -4
- data/app/helpers/simple_jwt_auth/users_helper.rb +0 -4
- data/app/jobs/simple_jwt_auth/application_job.rb +0 -4
- data/app/mailers/simple_jwt_auth/application_mailer.rb +0 -6
- data/app/models/simple_jwt_auth/application_record.rb +0 -5
- data/app/models/simple_jwt_auth/user.rb +0 -6
- data/app/views/layouts/simple_jwt_auth/application.html.erb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78d74d4d58750fc699e438212a1eb4d9f600c8aacebd23947e10b1ea5a8ab674
|
4
|
+
data.tar.gz: 4aa27eaeb5b1ead68fc77dd914ce12aee0ea75c180d7d9acd782f26b3e4839e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9610ecf297ae4156e6945b42aa659ecd5bc3d4cdc2ef453bec925054404f1ed48a91db1ebe1683ce06cb236766b4f14e6311d1fc7dd28219ccfc74f8fb6a6e38
|
7
|
+
data.tar.gz: 1beffab4245f75424b2c77f37e3468ed8d34c406ec62555f6efc7ecd6a35076be90dcb33f7ab52ca40f73188b601dd189b8b424bdb8b706cc7bf3c3dfe45f339
|
data/README.md
CHANGED
@@ -22,20 +22,15 @@ $ gem install simple_jwt_auth
|
|
22
22
|
### Models
|
23
23
|
After installation run
|
24
24
|
```bash
|
25
|
-
$ rails simple_jwt_auth:
|
25
|
+
$ rails simple_jwt_auth:setup
|
26
26
|
```
|
27
|
-
this will create a user model in your rails application.
|
27
|
+
this will create a user model in your rails application. As well as creating a file for adding associations and user model methods at app/models/user.rb
|
28
28
|
|
29
29
|
then run
|
30
30
|
```bash
|
31
31
|
$ rails db:migrate
|
32
32
|
```
|
33
|
-
|
34
|
-
in order to access gems provided routes add
|
35
|
-
```bash
|
36
|
-
mount SimpleJwtAuth::Engine, at: "/auth"
|
37
|
-
```
|
38
|
-
to the top of your routes in your rails project
|
33
|
+
|
39
34
|
### Creating Users
|
40
35
|
Users can be created by making a POST request to
|
41
36
|
https://localhost:3000/auth/users
|
@@ -1 +0,0 @@
|
|
1
|
-
//= link_directory ../stylesheets/simple_jwt_auth .css
|
File without changes
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_dependency "jwt"
|
2
|
+
|
3
|
+
class SessionsController < ApplicationController
|
4
|
+
def create
|
5
|
+
user = User.find_by(email: session_params[:email])
|
6
|
+
if user && user.authenticate(session_params[:password])
|
7
|
+
jwt = JWT.encode(
|
8
|
+
{
|
9
|
+
user_id: user.id, # the data to encode
|
10
|
+
exp: 24.hours.from_now.to_i # the expiration time
|
11
|
+
},
|
12
|
+
Rails.application.credentials.fetch(:secret_key_base), # the secret key
|
13
|
+
"HS256" # the encryption algorithm
|
14
|
+
)
|
15
|
+
render json: { jwt: jwt, email: user.email, user_id: user.id }, status: :created
|
16
|
+
else
|
17
|
+
render json: {}, status: :unauthorized
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def session_params
|
24
|
+
params.permit(:email, :password)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
def create
|
3
|
+
user = User.new(user_params)
|
4
|
+
|
5
|
+
if user.save
|
6
|
+
render json: {message: "User created successfully"}, status: :created
|
7
|
+
else
|
8
|
+
render json: {errors: user.errors.full_messages}, status: :bad_request
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def user_params
|
15
|
+
params.permit(:name, :email, :password, :password_confirmation)
|
16
|
+
end
|
17
|
+
end
|
data/app/models/user.rb
ADDED
data/config/routes.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module SimpleJwtAuth
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
|
4
|
-
initializer "actualize_auth.load_helpers" do |app|
|
3
|
+
initializer "simple_jwt_auth.load_helpers" do |app|
|
5
4
|
ActionController::Base.send :include, SimpleJwtAuth::Engine.helpers
|
6
5
|
end
|
7
6
|
end
|
@@ -3,18 +3,15 @@ require_dependency "tty-file"
|
|
3
3
|
desc "Copy migrations from simple_jwt_auth to application and create model/user.rb file in application"
|
4
4
|
namespace :simple_jwt_auth do
|
5
5
|
task :setup do
|
6
|
-
Rake::Task["
|
7
|
-
TTY::File.
|
8
|
-
TTY::File.create_file "app/models/simple_jwt_auth/user.rb" do
|
6
|
+
Rake::Task["simple_jwt_auth_engine:install:migrations"].invoke
|
7
|
+
TTY::File.create_file "app/models/user.rb" do
|
9
8
|
<<~CONFIG_MODELS
|
10
|
-
|
9
|
+
require File.expand_path('../../app/models/user', SimpleJwtAuth::Engine.called_from)
|
11
10
|
|
12
|
-
module SimpleJwtAuth
|
13
11
|
class User
|
14
|
-
#associations and user model methods here.
|
15
12
|
end
|
16
|
-
end
|
17
13
|
CONFIG_MODELS
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|
17
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_jwt_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- brye
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -91,22 +91,16 @@ files:
|
|
91
91
|
- README.md
|
92
92
|
- Rakefile
|
93
93
|
- app/assets/config/simple_jwt_auth_manifest.js
|
94
|
-
- app/assets/stylesheets/
|
95
|
-
- app/assets/stylesheets/
|
96
|
-
- app/
|
97
|
-
- app/controllers/
|
98
|
-
- app/
|
99
|
-
- app/controllers/simple_jwt_auth/users_controller.rb
|
94
|
+
- app/assets/stylesheets/sessions.css
|
95
|
+
- app/assets/stylesheets/users.css
|
96
|
+
- app/controllers/sessions_controller.rb
|
97
|
+
- app/controllers/users_controller.rb
|
98
|
+
- app/helpers/sessions_helper.rb
|
100
99
|
- app/helpers/simple_jwt_auth/application_helper.rb
|
101
|
-
- app/helpers/
|
102
|
-
- app/
|
103
|
-
- app/jobs/simple_jwt_auth/application_job.rb
|
104
|
-
- app/mailers/simple_jwt_auth/application_mailer.rb
|
105
|
-
- app/models/simple_jwt_auth/application_record.rb
|
106
|
-
- app/models/simple_jwt_auth/user.rb
|
107
|
-
- app/views/layouts/simple_jwt_auth/application.html.erb
|
100
|
+
- app/helpers/users_helper.rb
|
101
|
+
- app/models/user.rb
|
108
102
|
- config/routes.rb
|
109
|
-
- db/migrate/
|
103
|
+
- db/migrate/20191225083243_create_users.rb
|
110
104
|
- lib/simple_jwt_auth.rb
|
111
105
|
- lib/simple_jwt_auth/engine.rb
|
112
106
|
- lib/simple_jwt_auth/version.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
-
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
-
* It is generally better to create a new file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require_dependency "simple_jwt_auth/application_controller"
|
2
|
-
require_dependency "jwt"
|
3
|
-
|
4
|
-
module SimpleJwtAuth
|
5
|
-
class SessionsController < ApplicationController
|
6
|
-
def create
|
7
|
-
user = User.find_by(email: session_params[:email])
|
8
|
-
if user && user.authenticate(session_params[:password])
|
9
|
-
jwt = JWT.encode(
|
10
|
-
{
|
11
|
-
user_id: user.id, # the data to encode
|
12
|
-
exp: 24.hours.from_now.to_i # the expiration time
|
13
|
-
},
|
14
|
-
Rails.application.credentials.fetch(:secret_key_base), # the secret key
|
15
|
-
"HS256" # the encryption algorithm
|
16
|
-
)
|
17
|
-
render json: { jwt: jwt, email: user.email, user_id: user.id }, status: :created
|
18
|
-
else
|
19
|
-
render json: {}, status: :unauthorized
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def session_params
|
26
|
-
params.permit(:email, :password)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require_dependency "simple_jwt_auth/application_controller"
|
2
|
-
|
3
|
-
module SimpleJwtAuth
|
4
|
-
class UsersController < ApplicationController
|
5
|
-
|
6
|
-
def create
|
7
|
-
user = User.new(user_params)
|
8
|
-
|
9
|
-
if user.save
|
10
|
-
render json: {message: "User created successfully"}, status: :created
|
11
|
-
else
|
12
|
-
render json: {errors: user.errors.full_messages}, status: :bad_request
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def user_params
|
19
|
-
params.permit(:name, :email, :password, :password_confirmation)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Simple jwt auth</title>
|
5
|
-
<%= csrf_meta_tags %>
|
6
|
-
<%= csp_meta_tag %>
|
7
|
-
|
8
|
-
<%= stylesheet_link_tag "simple_jwt_auth/application", media: "all" %>
|
9
|
-
</head>
|
10
|
-
<body>
|
11
|
-
|
12
|
-
<%= yield %>
|
13
|
-
|
14
|
-
</body>
|
15
|
-
</html>
|