rails_jwt_api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -9
- data/app/controllers/{rails_jwt → rails_jwt_api}/application_controller.rb +1 -1
- data/app/controllers/{rails_jwt → rails_jwt_api}/users_controller.rb +5 -5
- data/app/mailers/rails_jwt/application_mailer.rb +1 -1
- data/config/routes.rb +1 -1
- data/lib/generators/{rails_jwt → rails_jwt_api}/install_generator.rb +6 -2
- data/lib/generators/{rails_jwt → rails_jwt_api}/templates/20211007002206_create_users.rb +0 -0
- data/lib/generators/{rails_jwt → rails_jwt_api}/templates/20211007002344_create_jwts.rb +0 -0
- data/lib/generators/{rails_jwt → rails_jwt_api}/templates/jwt.rb +0 -0
- data/lib/generators/rails_jwt_api/templates/rails_jwt_api.rb +13 -0
- data/lib/generators/{rails_jwt → rails_jwt_api}/templates/user.rb +0 -0
- data/lib/{rails_jwt → rails_jwt_api}/controllers/authentication.rb +5 -5
- data/lib/{rails_jwt → rails_jwt_api}/controllers/helpers.rb +2 -2
- data/lib/{rails_jwt → rails_jwt_api}/engine.rb +3 -3
- data/lib/rails_jwt_api/version.rb +3 -0
- data/lib/rails_jwt_api.rb +21 -0
- data/lib/tasks/{rails_jwt_tasks.rake → rails_jwt_api_tasks.rake} +1 -1
- metadata +19 -18
- data/lib/rails_jwt/version.rb +0 -3
- data/lib/rails_jwt.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 736b9008281b468ca1c766ce23062ff5c91bfd0f3d1d5c3d5440fb2e26b671e0
|
4
|
+
data.tar.gz: 540c0238035175f8c0b0646fbf6021cdef5708f976bafbc56e989e36f048ee3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82bb40fc879f13135f21a31de8661488078f3dd9a333e9262857a3d05d0711080a9122db1717f7f6b582b58b1c5d360fca264409183dc41597ad738354b94e8a
|
7
|
+
data.tar.gz: 7cca9e811867bc2df850d49caf55e7d7b386ee728db4cd60c2d048302e9117160bf924b346e83389317bff7706fb3a1011fb9e8a37652a17bf8984e7eef4ffbc
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# RailsJwtApi
|
2
2
|
|
3
3
|
## Work in progress
|
4
4
|
Simple jwt rails authentication
|
@@ -13,16 +13,16 @@ Simple jwt rails authentication
|
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
```ruby
|
16
|
-
gem '
|
16
|
+
gem 'rails_jwt_api', github: "https://github.com/Ispirett/rails_jwt"
|
17
17
|
or
|
18
|
-
gem '
|
18
|
+
gem 'rails_jwt_api'
|
19
19
|
```
|
20
20
|
then execute:
|
21
21
|
```bash
|
22
22
|
$ bundle
|
23
23
|
```
|
24
24
|
```bash
|
25
|
-
rails g
|
25
|
+
rails g rails_jwt_api:install
|
26
26
|
```
|
27
27
|
And then:
|
28
28
|
|
@@ -61,11 +61,11 @@ end
|
|
61
61
|
|
62
62
|
## Routes
|
63
63
|
* This gem adds routes to your routes file like so.
|
64
|
-
* Sign Up /
|
65
|
-
* Sign In /
|
64
|
+
* Sign Up /rails_jwt_api/auth/sign_up
|
65
|
+
* Sign In /rails_jwt_api/auth/sign_in
|
66
66
|
|
67
67
|
```ruby
|
68
|
-
mount
|
68
|
+
mount RailsJwtApi::Engine => "/rails_jwt_api", as: :rails_jwt
|
69
69
|
```
|
70
70
|
|
71
71
|
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
##### Sign Up
|
77
77
|
|
78
78
|
```html
|
79
|
-
|
79
|
+
rails_jwt_api/auth/sign_up
|
80
80
|
```
|
81
81
|
|
82
82
|
```json
|
@@ -98,7 +98,7 @@ rails_jwt/auth/sign_up
|
|
98
98
|
|
99
99
|
## Sign In
|
100
100
|
```html
|
101
|
-
|
101
|
+
rails_jwt_api/auth/sign_in
|
102
102
|
|
103
103
|
```
|
104
104
|
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require_dependency "
|
1
|
+
require_dependency "rails_jwt_api/application_controller"
|
2
2
|
|
3
|
-
module
|
3
|
+
module RailsJwtApi
|
4
4
|
class UsersController < ApplicationController
|
5
|
-
include
|
5
|
+
include RailsJwtApi::Controllers::Authentication
|
6
6
|
skip_before_action :verify_authenticity_token
|
7
7
|
before_action :check_passwords, only: :create
|
8
|
-
# gem '
|
8
|
+
# gem 'rails_jwt_api', path:'/Users/ispirett/RubymineProjects/engines/rails_jwt'
|
9
9
|
|
10
10
|
def create
|
11
11
|
@user = User.new(user_params)
|
12
12
|
if @user.save
|
13
13
|
token = encode(user_id: @user.id)
|
14
14
|
# refactor to allow users to configure
|
15
|
-
time = Time.now +
|
15
|
+
time = Time.now + RailsJwtApi.token_expiration.to_i
|
16
16
|
render json: {status: 'success', token: token,user: @user.details, exp: time.strftime('%m %d %y %H:%M')}, status: :ok
|
17
17
|
else
|
18
18
|
render json: {status: :failed, msg: @user.errors.full_messages}, status: :unauthorized
|
data/config/routes.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
module
|
1
|
+
module RailsJwtApi
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
3
3
|
source_root File.expand_path('templates', __dir__)
|
4
4
|
|
5
5
|
def install_route
|
6
|
-
route 'mount
|
6
|
+
route 'mount RailsJwtApi::Engine => "/rails_jwt_api", as: :rails_jwt_api'
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate_config_file
|
10
|
+
copy_file "rails_jwt_api.rb", "config/initializers/rails_jwt_api.rb"
|
7
11
|
end
|
8
12
|
|
9
13
|
def copy_user_model
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
RailsJwtApi.setup do |config|
|
2
|
+
|
3
|
+
# Token Expiration date
|
4
|
+
# ---------------------------
|
5
|
+
# Token will expire on the date you set .
|
6
|
+
config.token_expiration = 2.weeks.from_now # Default
|
7
|
+
|
8
|
+
# Token secret key
|
9
|
+
# -------------------
|
10
|
+
# This key will be used to sign all jwt tokens created
|
11
|
+
config.token_secret_key = Rails.application.secret_key_base # Default
|
12
|
+
|
13
|
+
end
|
File without changes
|
@@ -1,17 +1,17 @@
|
|
1
|
-
module
|
1
|
+
module RailsJwtApi
|
2
2
|
module Controllers
|
3
3
|
module Authentication
|
4
4
|
|
5
|
-
|
5
|
+
|
6
6
|
# TODO refactor to allow users to ad there own expiration date
|
7
|
-
def encode(payout, exp =
|
7
|
+
def encode(payout, exp = RailsJwtApi.token_expiration)
|
8
8
|
payout[:exp] = exp.to_i
|
9
|
-
JWT.encode(payout,
|
9
|
+
JWT.encode(payout, RailsJwtApi.token_secret_key)
|
10
10
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def decode(token)
|
14
|
-
decode = JWT.decode(token,
|
14
|
+
decode = JWT.decode(token,RailsJwtApi.token_secret_key)[0]
|
15
15
|
HashWithIndifferentAccess.new decode
|
16
16
|
end
|
17
17
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module
|
2
|
+
module RailsJwtApi
|
3
3
|
module Controllers
|
4
4
|
module Helpers
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
include
|
6
|
+
include RailsJwtApi::Controllers::Authentication
|
7
7
|
|
8
8
|
included do
|
9
9
|
def authorize_user!
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module RailsJwtApi
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
isolate_namespace
|
3
|
+
isolate_namespace RailsJwtApi
|
4
4
|
|
5
5
|
config.generators do |g|
|
6
6
|
g.test_framework :rspec, fixture: false
|
@@ -9,6 +9,6 @@ module RailsJwt
|
|
9
9
|
g.helper false
|
10
10
|
g.template_engine false
|
11
11
|
end
|
12
|
-
ActionController::Base.send :include,
|
12
|
+
ActionController::Base.send :include, RailsJwtApi::Controllers::Helpers
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rails_jwt_api/version"
|
2
|
+
require 'Jwt'
|
3
|
+
require 'bcrypt'
|
4
|
+
require 'rails_jwt_api/controllers/authentication'
|
5
|
+
require 'rails_jwt_api/controllers/helpers'
|
6
|
+
require "rails_jwt_api/engine"
|
7
|
+
require 'rails'
|
8
|
+
|
9
|
+
module RailsJwtApi
|
10
|
+
mattr_accessor :token_expiration, default: 1.month.from_now
|
11
|
+
mattr_accessor :token_secret_key, default: -> {Rails.application.secret_key_base}
|
12
|
+
|
13
|
+
module Controllers
|
14
|
+
autoload :Authentication, 'rails_jwt_api/controllers/authentication'
|
15
|
+
autoload :Helpers, 'rails_jwt_api/controllers/helpers'
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.config
|
19
|
+
yield_self
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_jwt_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ispirett
|
@@ -83,29 +83,30 @@ files:
|
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
85
|
- app/controllers/concerns/controller_helpers.rb
|
86
|
-
- app/controllers/
|
87
|
-
- app/controllers/
|
86
|
+
- app/controllers/rails_jwt_api/application_controller.rb
|
87
|
+
- app/controllers/rails_jwt_api/users_controller.rb
|
88
88
|
- app/mailers/rails_jwt/application_mailer.rb
|
89
89
|
- config/routes.rb
|
90
|
-
- lib/generators/
|
91
|
-
- lib/generators/
|
92
|
-
- lib/generators/
|
93
|
-
- lib/generators/
|
94
|
-
- lib/generators/
|
95
|
-
- lib/
|
96
|
-
- lib/
|
97
|
-
- lib/
|
98
|
-
- lib/
|
99
|
-
- lib/
|
100
|
-
- lib/
|
101
|
-
|
90
|
+
- lib/generators/rails_jwt_api/install_generator.rb
|
91
|
+
- lib/generators/rails_jwt_api/templates/20211007002206_create_users.rb
|
92
|
+
- lib/generators/rails_jwt_api/templates/20211007002344_create_jwts.rb
|
93
|
+
- lib/generators/rails_jwt_api/templates/jwt.rb
|
94
|
+
- lib/generators/rails_jwt_api/templates/rails_jwt_api.rb
|
95
|
+
- lib/generators/rails_jwt_api/templates/user.rb
|
96
|
+
- lib/rails_jwt_api.rb
|
97
|
+
- lib/rails_jwt_api/controllers/authentication.rb
|
98
|
+
- lib/rails_jwt_api/controllers/helpers.rb
|
99
|
+
- lib/rails_jwt_api/engine.rb
|
100
|
+
- lib/rails_jwt_api/version.rb
|
101
|
+
- lib/tasks/rails_jwt_api_tasks.rake
|
102
|
+
homepage: https://github.com/Ispirett/rails_jwt_api
|
102
103
|
licenses:
|
103
104
|
- MIT
|
104
105
|
metadata:
|
105
106
|
allowed_push_host: https://rubygems.org
|
106
|
-
homepage_uri: https://github.com/Ispirett/
|
107
|
-
source_code_uri: https://github.com/Ispirett/
|
108
|
-
changelog_uri: https://github.com/Ispirett/
|
107
|
+
homepage_uri: https://github.com/Ispirett/rails_jwt_api
|
108
|
+
source_code_uri: https://github.com/Ispirett/rails_jwt_api
|
109
|
+
changelog_uri: https://github.com/Ispirett/rails_jwt_api/CHANGELOG.md
|
109
110
|
post_install_message:
|
110
111
|
rdoc_options: []
|
111
112
|
require_paths:
|
data/lib/rails_jwt/version.rb
DELETED
data/lib/rails_jwt.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require "rails_jwt/version"
|
2
|
-
require 'Jwt'
|
3
|
-
require 'bcrypt'
|
4
|
-
require 'rails_jwt/controllers/authentication'
|
5
|
-
require 'rails_jwt/controllers/helpers'
|
6
|
-
require "rails_jwt/engine"
|
7
|
-
|
8
|
-
module RailsJwt
|
9
|
-
module Controllers
|
10
|
-
autoload :Authentication, 'rails_jwt/controllers/authentication'
|
11
|
-
autoload :Helpers, 'rails_jwt/controllers/helpers'
|
12
|
-
end
|
13
|
-
end
|