api_guard 0.2.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +95 -15
  3. data/Rakefile +2 -5
  4. data/app/controllers/api_guard/application_controller.rb +2 -0
  5. data/app/controllers/api_guard/authentication_controller.rb +6 -4
  6. data/app/controllers/api_guard/passwords_controller.rb +4 -2
  7. data/app/controllers/api_guard/registration_controller.rb +4 -2
  8. data/app/controllers/api_guard/tokens_controller.rb +5 -3
  9. data/config/locales/en.yml +22 -0
  10. data/config/routes.rb +2 -0
  11. data/lib/api_guard.rb +11 -6
  12. data/lib/api_guard/app_secret_key.rb +22 -0
  13. data/lib/api_guard/engine.rb +4 -5
  14. data/lib/api_guard/jwt_auth/authentication.rb +34 -12
  15. data/lib/api_guard/jwt_auth/blacklist_token.rb +7 -3
  16. data/lib/api_guard/jwt_auth/json_web_token.rb +11 -5
  17. data/lib/api_guard/jwt_auth/refresh_jwt_token.rb +4 -0
  18. data/lib/api_guard/models/concerns.rb +8 -6
  19. data/lib/api_guard/modules.rb +13 -11
  20. data/lib/api_guard/resource_mapper.rb +3 -1
  21. data/lib/api_guard/response_formatters/renderer.rb +5 -2
  22. data/lib/api_guard/route_mapper.rb +58 -54
  23. data/lib/api_guard/test/controller_helper.rb +2 -0
  24. data/lib/api_guard/version.rb +3 -1
  25. data/lib/generators/api_guard/controllers/controllers_generator.rb +9 -7
  26. data/lib/generators/api_guard/controllers/templates/authentication_controller.rb +4 -4
  27. data/lib/generators/api_guard/controllers/templates/passwords_controller.rb +3 -3
  28. data/lib/generators/api_guard/controllers/templates/registration_controller.rb +3 -3
  29. data/lib/generators/api_guard/controllers/templates/tokens_controller.rb +7 -4
  30. data/lib/generators/api_guard/initializer/initializer_generator.rb +3 -1
  31. data/lib/generators/api_guard/initializer/templates/initializer.rb +6 -4
  32. metadata +54 -69
  33. data/app/models/api_guard/application_record.rb +0 -5
  34. data/app/views/layouts/api_guard/application.html.erb +0 -14
@@ -6,22 +6,22 @@ module <%= @controller_scope %>
6
6
  # def create
7
7
  # if resource.authenticate(params[:password])
8
8
  # create_token_and_set_header(resource, resource_name)
9
- # render_success(data: resource)
9
+ # render_success(message: I18n.t('api_guard.authentication.signed_in'))
10
10
  # else
11
- # render_error(422, message: 'Invalid login credentials')
11
+ # render_error(422, message: I18n.t('api_guard.authentication.invalid_login_credentials'))
12
12
  # end
13
13
  # end
14
14
 
15
15
  # def destroy
16
16
  # blacklist_token
17
- # render_success(message: 'Signed out successfully')
17
+ # render_success(message: I18n.t('api_guard.authentication.signed_out'))
18
18
  # end
19
19
 
20
20
  # private
21
21
 
22
22
  # def find_resource
23
23
  # self.resource = resource_class.find_by(email: params[:email].downcase.strip) if params[:email].present?
24
- # render_error(422, message: 'Invalid login credentials') unless resource
24
+ # render_error(422, message: I18n.t('api_guard.authentication.invalid_login_credentials')) unless resource
25
25
  # end
26
26
  end
27
27
  end
@@ -6,11 +6,11 @@ module <%= @controller_scope %>
6
6
  # invalidate_old_jwt_tokens(current_resource)
7
7
  #
8
8
  # if current_resource.update_attributes(password_params)
9
- # blacklist_token
9
+ # blacklist_token unless ApiGuard.invalidate_old_tokens_on_password_change
10
10
  # destroy_all_refresh_tokens(current_resource)
11
11
  #
12
12
  # create_token_and_set_header(current_resource, resource_name)
13
- # render_success(data: current_resource)
13
+ # render_success(message: I18n.t('api_guard.password.changed'))
14
14
  # else
15
15
  # render_error(422, object: current_resource)
16
16
  # end
@@ -19,7 +19,7 @@ module <%= @controller_scope %>
19
19
  # private
20
20
 
21
21
  # def password_params
22
- # params.require(resource_name.to_sym).permit(:password, :password_confirmation)
22
+ # params.permit(:password, :password_confirmation)
23
23
  # end
24
24
  end
25
25
  end
@@ -6,7 +6,7 @@ module <%= @controller_scope %>
6
6
  # init_resource(sign_up_params)
7
7
  # if resource.save
8
8
  # create_token_and_set_header(resource, resource_name)
9
- # render_success(data: resource, message: "#{resource_name.capitalize} created successfully")
9
+ # render_success(message: I18n.t('api_guard.registration.signed_up'))
10
10
  # else
11
11
  # render_error(422, object: resource)
12
12
  # end
@@ -14,13 +14,13 @@ module <%= @controller_scope %>
14
14
 
15
15
  # def destroy
16
16
  # current_resource.destroy
17
- # render_success(message: "#{resource_name.capitalize} destroyed successfully")
17
+ # render_success(message: I18n.t('api_guard.registration.account_deleted'))
18
18
  # end
19
19
 
20
20
  # private
21
21
 
22
22
  # def sign_up_params
23
- # params.require(resource_name.to_sym).permit(:email, :password, :password_confirmation)
23
+ # params.permit(:email, :password, :password_confirmation)
24
24
  # end
25
25
  end
26
26
  end
@@ -4,9 +4,12 @@ module <%= @controller_scope %>
4
4
  # before_action :find_refresh_token, only: [:create]
5
5
 
6
6
  # def create
7
- # @refresh_token.destroy
8
7
  # create_token_and_set_header(current_resource, resource_name)
9
- # render_success(data: current_resource)
8
+ #
9
+ # @refresh_token.destroy
10
+ # blacklist_token if ApiGuard.blacklist_token_after_refreshing
11
+ #
12
+ # render_success(message: I18n.t('api_guard.access_token.refreshed'))
10
13
  # end
11
14
 
12
15
  # private
@@ -16,9 +19,9 @@ module <%= @controller_scope %>
16
19
  #
17
20
  # if refresh_token_from_header
18
21
  # @refresh_token = find_refresh_token_of(current_resource, refresh_token_from_header)
19
- # return render_error(401, message: 'Invalid refresh token') unless @refresh_token
22
+ # return render_error(401, message: I18n.t('api_guard.refresh_token.invalid')) unless @refresh_token
20
23
  # else
21
- # render_error(401, message: 'Refresh token is missing in the request')
24
+ # render_error(401, message: I18n.t('api_guard.refresh_token.missing'))
22
25
  # end
23
26
  # end
24
27
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ApiGuard
2
4
  class InitializerGenerator < Rails::Generators::Base
3
- source_root File.expand_path('../templates', __FILE__)
5
+ source_root File.expand_path('templates', __dir__)
4
6
 
5
7
  desc 'Creates initializer for configuring API Guard'
6
8
 
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ApiGuard.setup do |config|
2
4
  # Validity of the JWT access token
3
5
  # Default: 1 day
4
- config.token_validity = 1.day
6
+ # config.token_validity = 1.day
5
7
 
6
8
  # Secret key for signing (encoding & decoding) the JWT access token
7
9
  # Default: 'secret_key_base' from Rails secrets
8
- config.token_signing_secret = Rails.application.secrets.secret_key_base
10
+ # config.token_signing_secret = 'my_signing_secret'
9
11
 
10
12
  # Invalidate old tokens on changing the password
11
13
  # Default: false
12
- config.invalidate_old_tokens_on_password_change = false
14
+ # config.invalidate_old_tokens_on_password_change = false
13
15
 
14
16
  # Blacklist JWT access token after refreshing
15
17
  # Default: false
16
- config.blacklist_token_after_refreshing = false
18
+ # config.blacklist_token_after_refreshing = false
17
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_guard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gokul Murali
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-22 00:00:00.000000000 Z
11
+ date: 2020-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -16,140 +16,126 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.1.0
19
+ version: '2.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '2.1'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.1.0
26
+ version: '2.2'
33
27
  - !ruby/object:Gem::Dependency
34
- name: rails
28
+ name: bcrypt
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '5.1'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 5.1.5
33
+ version: '3.1'
43
34
  type: :development
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
38
  - - "~>"
48
39
  - !ruby/object:Gem::Version
49
- version: '5.1'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 5.1.5
40
+ version: '3.1'
53
41
  - !ruby/object:Gem::Dependency
54
- name: sqlite3
42
+ name: factory_bot_rails
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
45
  - - "~>"
58
46
  - !ruby/object:Gem::Version
59
- version: '1.3'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.3.13
47
+ version: '6.1'
63
48
  type: :development
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
66
51
  requirements:
67
52
  - - "~>"
68
53
  - !ruby/object:Gem::Version
69
- version: '1.3'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 1.3.13
54
+ version: '6.1'
73
55
  - !ruby/object:Gem::Dependency
74
- name: bcrypt
56
+ name: rails
75
57
  requirement: !ruby/object:Gem::Requirement
76
58
  requirements:
77
59
  - - "~>"
78
60
  - !ruby/object:Gem::Version
79
- version: '3.1'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 3.1.11
61
+ version: '6.0'
83
62
  type: :development
84
63
  prerelease: false
85
64
  version_requirements: !ruby/object:Gem::Requirement
86
65
  requirements:
87
66
  - - "~>"
88
67
  - !ruby/object:Gem::Version
89
- version: '3.1'
90
- - - ">="
68
+ version: '6.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: listen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
91
81
  - !ruby/object:Gem::Version
92
- version: 3.1.11
82
+ version: '3.2'
93
83
  - !ruby/object:Gem::Dependency
94
84
  name: rspec-rails
95
85
  requirement: !ruby/object:Gem::Requirement
96
86
  requirements:
97
87
  - - "~>"
98
88
  - !ruby/object:Gem::Version
99
- version: '3.7'
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: 3.7.2
89
+ version: '4.0'
103
90
  type: :development
104
91
  prerelease: false
105
92
  version_requirements: !ruby/object:Gem::Requirement
106
93
  requirements:
107
94
  - - "~>"
108
95
  - !ruby/object:Gem::Version
109
- version: '3.7'
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 3.7.2
96
+ version: '4.0'
113
97
  - !ruby/object:Gem::Dependency
114
- name: factory_bot_rails
98
+ name: rubocop
115
99
  requirement: !ruby/object:Gem::Requirement
116
100
  requirements:
117
101
  - - "~>"
118
102
  - !ruby/object:Gem::Version
119
- version: '4.8'
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: 4.8.2
103
+ version: 0.75.1
123
104
  type: :development
124
105
  prerelease: false
125
106
  version_requirements: !ruby/object:Gem::Requirement
126
107
  requirements:
127
108
  - - "~>"
128
109
  - !ruby/object:Gem::Version
129
- version: '4.8'
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: 4.8.2
110
+ version: 0.75.1
133
111
  - !ruby/object:Gem::Dependency
134
112
  name: simplecov
135
113
  requirement: !ruby/object:Gem::Requirement
136
114
  requirements:
137
- - - "~>"
115
+ - - '='
138
116
  - !ruby/object:Gem::Version
139
- version: '0.16'
140
- - - ">="
141
- - !ruby/object:Gem::Version
142
- version: 0.16.1
117
+ version: '0.17'
143
118
  type: :development
144
119
  prerelease: false
145
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: '0.17'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
146
128
  requirements:
147
129
  - - "~>"
148
130
  - !ruby/object:Gem::Version
149
- version: '0.16'
150
- - - ">="
131
+ version: '1.4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: 0.16.1
138
+ version: '1.4'
153
139
  description: JWT authentication solution for Rails APIs
154
140
  email:
155
141
  - m.gokul595@gmail.com
@@ -165,10 +151,10 @@ files:
165
151
  - app/controllers/api_guard/passwords_controller.rb
166
152
  - app/controllers/api_guard/registration_controller.rb
167
153
  - app/controllers/api_guard/tokens_controller.rb
168
- - app/models/api_guard/application_record.rb
169
- - app/views/layouts/api_guard/application.html.erb
154
+ - config/locales/en.yml
170
155
  - config/routes.rb
171
156
  - lib/api_guard.rb
157
+ - lib/api_guard/app_secret_key.rb
172
158
  - lib/api_guard/engine.rb
173
159
  - lib/api_guard/jwt_auth/authentication.rb
174
160
  - lib/api_guard/jwt_auth/blacklist_token.rb
@@ -194,7 +180,7 @@ homepage: https://github.com/Gokul595/api_guard
194
180
  licenses:
195
181
  - MIT
196
182
  metadata: {}
197
- post_install_message:
183
+ post_install_message:
198
184
  rdoc_options: []
199
185
  require_paths:
200
186
  - lib
@@ -202,16 +188,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
188
  requirements:
203
189
  - - ">="
204
190
  - !ruby/object:Gem::Version
205
- version: 2.3.0
191
+ version: 2.5.0
206
192
  required_rubygems_version: !ruby/object:Gem::Requirement
207
193
  requirements:
208
194
  - - ">="
209
195
  - !ruby/object:Gem::Version
210
196
  version: '0'
211
197
  requirements: []
212
- rubyforge_project:
213
- rubygems_version: 2.6.14
214
- signing_key:
198
+ rubygems_version: 3.0.8
199
+ signing_key:
215
200
  specification_version: 4
216
201
  summary: Rails API authentication made easy
217
202
  test_files: []
@@ -1,5 +0,0 @@
1
- module ApiGuard
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
5
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>API Guard</title>
5
- <%= stylesheet_link_tag "api_guard/application", media: "all" %>
6
- <%= javascript_include_tag "api_guard/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>