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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af88f3eabdd9d3cf16232a95df27e4fe756a03be4b026d6ee2b1f67769d0e2af
4
- data.tar.gz: 3b736a2f37539db880526d007db3da97549b01acaa98552d36a76aaf9d0848e5
3
+ metadata.gz: 736b9008281b468ca1c766ce23062ff5c91bfd0f3d1d5c3d5440fb2e26b671e0
4
+ data.tar.gz: 540c0238035175f8c0b0646fbf6021cdef5708f976bafbc56e989e36f048ee3e
5
5
  SHA512:
6
- metadata.gz: 3f0826478a29ce646bd3a15c6c8fc4164c95088d742f466dd57a8d8533846101769a3b3904f55fe03f3678d3e04a6f3b04af559bbfce466f4cc549593ebd9b12
7
- data.tar.gz: 19be679c9daa4e716fa43eb9bd185a09e21a3c966470bf619d98ec19eb8a07ae94eac6636af6c528ad1e82a068bde11a7e01d78b34e9c02a52a9ee9e43c6c6a9
6
+ metadata.gz: 82bb40fc879f13135f21a31de8661488078f3dd9a333e9262857a3d05d0711080a9122db1717f7f6b582b58b1c5d360fca264409183dc41597ad738354b94e8a
7
+ data.tar.gz: 7cca9e811867bc2df850d49caf55e7d7b386ee728db4cd60c2d048302e9117160bf924b346e83389317bff7706fb3a1011fb9e8a37652a17bf8984e7eef4ffbc
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rails_javascript_web_tokens
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 'rails_javascript_web_tokens', github: "https://github.com/Ispirett/rails_jwt"
16
+ gem 'rails_jwt_api', github: "https://github.com/Ispirett/rails_jwt"
17
17
  or
18
- gem 'rails_javascript_web_tokens'
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 rails_jwt:install
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 /rails_jwt/auth/sign_up
65
- * Sign In /rails_jwt/auth/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 RailsJwt::Engine => "/rails_jwt", as: :rails_jwt
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
- rails_jwt/auth/sign_up
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
- rails_jwt/auth/sign_in
101
+ rails_jwt_api/auth/sign_in
102
102
 
103
103
  ```
104
104
 
@@ -1,4 +1,4 @@
1
- module RailsJwt
1
+ module RailsJwtApi
2
2
  class ApplicationController < ::ActionController::Base
3
3
  end
4
4
  end
@@ -1,18 +1,18 @@
1
- require_dependency "rails_jwt/application_controller"
1
+ require_dependency "rails_jwt_api/application_controller"
2
2
 
3
- module RailsJwt
3
+ module RailsJwtApi
4
4
  class UsersController < ApplicationController
5
- include RailsJwt::Controllers::Authentication
5
+ include RailsJwtApi::Controllers::Authentication
6
6
  skip_before_action :verify_authenticity_token
7
7
  before_action :check_passwords, only: :create
8
- # gem 'rails_jwt', path:'/Users/ispirett/RubymineProjects/engines/rails_jwt'
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 + 1.week.from_now.to_i
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
@@ -1,4 +1,4 @@
1
- module RailsJwt
1
+ module RailsJwtApi
2
2
  class ApplicationMailer < ActionMailer::Base
3
3
  default from: 'from@example.com'
4
4
  layout 'mailer'
data/config/routes.rb CHANGED
@@ -1,4 +1,4 @@
1
- RailsJwt::Engine.routes.draw do
1
+ RailsJwtApi::Engine.routes.draw do
2
2
  match '/auth/sign_in' => "users#sign_in", via: :get, as: :sign_in
3
3
  match '/auth/sign_up' => "users#create", via: :post, as: :sign_up
4
4
  end
@@ -1,9 +1,13 @@
1
- module RailsJwt
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 RailsJwt::Engine => "/rails_jwt", as: :rails_jwt'
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
@@ -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
@@ -1,17 +1,17 @@
1
- module RailsJwt
1
+ module RailsJwtApi
2
2
  module Controllers
3
3
  module Authentication
4
4
 
5
- SECRET_KEY = ENV.fetch("RAILS_JWT_TOKEN", 'development')
5
+
6
6
  # TODO refactor to allow users to ad there own expiration date
7
- def encode(payout, exp = 1.month.from_now)
7
+ def encode(payout, exp = RailsJwtApi.token_expiration)
8
8
  payout[:exp] = exp.to_i
9
- JWT.encode(payout, SECRET_KEY)
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, SECRET_KEY)[0]
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 RailsJwt
2
+ module RailsJwtApi
3
3
  module Controllers
4
4
  module Helpers
5
5
  extend ActiveSupport::Concern
6
- include RailsJwt::Controllers::Authentication
6
+ include RailsJwtApi::Controllers::Authentication
7
7
 
8
8
  included do
9
9
  def authorize_user!
@@ -1,6 +1,6 @@
1
- module RailsJwt
1
+ module RailsJwtApi
2
2
  class Engine < ::Rails::Engine
3
- isolate_namespace RailsJwt
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, RailsJwt::Controllers::Helpers
12
+ ActionController::Base.send :include, RailsJwtApi::Controllers::Helpers
13
13
  end
14
14
  end
@@ -0,0 +1,3 @@
1
+ module RailsJwtApi
2
+ VERSION = '0.1.1'
3
+ 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
@@ -1,4 +1,4 @@
1
1
  # desc "Explaining what the task does"
2
- # task :rails_jwt do
2
+ # task :rails_jwt_api do
3
3
  # # Task goes here
4
4
  # 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.0
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/rails_jwt/application_controller.rb
87
- - app/controllers/rails_jwt/users_controller.rb
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/rails_jwt/install_generator.rb
91
- - lib/generators/rails_jwt/templates/20211007002206_create_users.rb
92
- - lib/generators/rails_jwt/templates/20211007002344_create_jwts.rb
93
- - lib/generators/rails_jwt/templates/jwt.rb
94
- - lib/generators/rails_jwt/templates/user.rb
95
- - lib/rails_jwt.rb
96
- - lib/rails_jwt/controllers/authentication.rb
97
- - lib/rails_jwt/controllers/helpers.rb
98
- - lib/rails_jwt/engine.rb
99
- - lib/rails_jwt/version.rb
100
- - lib/tasks/rails_jwt_tasks.rake
101
- homepage: https://github.com/Ispirett/rails_jwt
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/rails_jwt
107
- source_code_uri: https://github.com/Ispirett/rails_jwt
108
- changelog_uri: https://github.com/Ispirett/rails_jwt/CHANGELOG.md
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:
@@ -1,3 +0,0 @@
1
- module RailsJwt
2
- VERSION = '0.1.0'
3
- end
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