jwt_auth_engine 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +422 -0
- data/app/controllers/concerns/jwt_auth_engine/authenticatable.rb +52 -0
- data/app/controllers/concerns/jwt_auth_engine/rescuable.rb +23 -0
- data/app/controllers/concerns/jwt_auth_engine/response_renderable.rb +29 -0
- data/app/controllers/concerns/jwt_auth_engine/serializable.rb +21 -0
- data/app/controllers/concerns/jwt_auth_engine/tokenizable.rb +22 -0
- data/app/controllers/jwt_auth_engine/application_controller.rb +21 -0
- data/app/controllers/jwt_auth_engine/passwords_controller.rb +26 -0
- data/app/controllers/jwt_auth_engine/ping_controller.rb +21 -0
- data/app/controllers/jwt_auth_engine/profiles_controller.rb +15 -0
- data/app/controllers/jwt_auth_engine/registrations_controller.rb +33 -0
- data/app/controllers/jwt_auth_engine/sessions_controller.rb +41 -0
- data/app/controllers/jwt_auth_engine/tokens_controller.rb +21 -0
- data/app/services/jwt_auth_engine/base_service.rb +26 -0
- data/app/services/jwt_auth_engine/change_password_service.rb +48 -0
- data/app/services/jwt_auth_engine/login_service.rb +46 -0
- data/app/services/jwt_auth_engine/refresh_token_service.rb +35 -0
- data/app/services/jwt_auth_engine/signup_service.rb +23 -0
- data/app/services/jwt_auth_engine/token_service.rb +72 -0
- data/config/routes.rb +47 -0
- data/lib/generators/jwt_auth_engine/install/install_generator.rb +95 -0
- data/lib/generators/jwt_auth_engine/install/templates/add_jwt_auth_engine_columns_migration.rb.tt +11 -0
- data/lib/generators/jwt_auth_engine/install/templates/auth_model_concern.rb.tt +32 -0
- data/lib/generators/jwt_auth_engine/install/templates/jwt_auth_engine_initializer.rb.tt +22 -0
- data/lib/jwt_auth_engine/configuration.rb +50 -0
- data/lib/jwt_auth_engine/constants.rb +16 -0
- data/lib/jwt_auth_engine/engine.rb +10 -0
- data/lib/jwt_auth_engine/errors.rb +14 -0
- data/lib/jwt_auth_engine/version.rb +5 -0
- data/lib/jwt_auth_engine.rb +79 -0
- data/sig/jwt_auth_engine.rbs +4 -0
- metadata +137 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module JwtAuthEngine
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
class AuthModelNotFound < Error; end
|
|
7
|
+
class InvalidAuthModel < Error; end
|
|
8
|
+
|
|
9
|
+
class InvalidToken < Error; end
|
|
10
|
+
class TokenExpired < Error; end
|
|
11
|
+
class InvalidTokenType < Error; end
|
|
12
|
+
|
|
13
|
+
class MissingSecretKey < Error; end
|
|
14
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'jwt_auth_engine/version'
|
|
4
|
+
require_relative 'jwt_auth_engine/engine'
|
|
5
|
+
require_relative 'jwt_auth_engine/errors'
|
|
6
|
+
require_relative 'jwt_auth_engine/constants'
|
|
7
|
+
require_relative 'jwt_auth_engine/configuration'
|
|
8
|
+
|
|
9
|
+
# Public configuration and model-resolution API for the auth engine.
|
|
10
|
+
module JwtAuthEngine
|
|
11
|
+
class << self
|
|
12
|
+
def configuration
|
|
13
|
+
@configuration ||= Configuration.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def configure
|
|
17
|
+
yield(configuration)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def auth_model_class
|
|
21
|
+
configured_auth_model = configuration.auth_model.to_s
|
|
22
|
+
return @resolved_auth_model_class if cached_auth_model_class?(configured_auth_model)
|
|
23
|
+
|
|
24
|
+
resolve_and_cache_auth_model(configured_auth_model)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def auth_model_name
|
|
28
|
+
auth_model_class.name.underscore.to_sym
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def identifier_field
|
|
32
|
+
configuration.identifier_field.to_sym
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def password_field
|
|
36
|
+
configuration.password_field.to_sym
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def password_digest_field
|
|
40
|
+
:"#{password_field}_digest"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def current_password_field
|
|
44
|
+
:"current_#{password_field}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def new_password_field
|
|
48
|
+
:"new_#{password_field}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def auth_model_token_payload_key
|
|
52
|
+
:"#{auth_model_name}_#{auth_model_class.primary_key}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def cached_auth_model_class?(configured_auth_model)
|
|
58
|
+
defined?(@resolved_auth_model_class) && @resolved_auth_model_name == configured_auth_model
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def resolve_and_cache_auth_model(configured_auth_model)
|
|
62
|
+
klass = configured_auth_model.constantize
|
|
63
|
+
ensure_valid_auth_model!(klass)
|
|
64
|
+
|
|
65
|
+
@resolved_auth_model_name = configured_auth_model
|
|
66
|
+
@resolved_auth_model_class = klass
|
|
67
|
+
rescue NameError
|
|
68
|
+
raise AuthModelNotFound,
|
|
69
|
+
"Configured auth_model '#{configuration.auth_model}' could not be constantized"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def ensure_valid_auth_model!(klass)
|
|
73
|
+
return if klass < ActiveRecord::Base
|
|
74
|
+
|
|
75
|
+
raise InvalidAuthModel,
|
|
76
|
+
"Configured auth_model '#{configuration.auth_model}' must inherit from ActiveRecord::Base"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jwt_auth_engine
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Abhishek Kushwaha
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-06-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bcrypt
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 3.1.18
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '4.0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 3.1.18
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '4.0'
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: jwt
|
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 2.9.0
|
|
40
|
+
- - "<"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '3.0'
|
|
43
|
+
type: :runtime
|
|
44
|
+
prerelease: false
|
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 2.9.0
|
|
50
|
+
- - "<"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '3.0'
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
54
|
+
name: rails
|
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 6.1.0
|
|
60
|
+
type: :runtime
|
|
61
|
+
prerelease: false
|
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: 6.1.0
|
|
67
|
+
description: Provides plug-and-play JWT authentication endpoints for Rails API apps
|
|
68
|
+
using your host auth model.
|
|
69
|
+
email:
|
|
70
|
+
- abhiskush@gmail.com
|
|
71
|
+
executables: []
|
|
72
|
+
extensions: []
|
|
73
|
+
extra_rdoc_files: []
|
|
74
|
+
files:
|
|
75
|
+
- CHANGELOG.md
|
|
76
|
+
- LICENSE.txt
|
|
77
|
+
- README.md
|
|
78
|
+
- app/controllers/concerns/jwt_auth_engine/authenticatable.rb
|
|
79
|
+
- app/controllers/concerns/jwt_auth_engine/rescuable.rb
|
|
80
|
+
- app/controllers/concerns/jwt_auth_engine/response_renderable.rb
|
|
81
|
+
- app/controllers/concerns/jwt_auth_engine/serializable.rb
|
|
82
|
+
- app/controllers/concerns/jwt_auth_engine/tokenizable.rb
|
|
83
|
+
- app/controllers/jwt_auth_engine/application_controller.rb
|
|
84
|
+
- app/controllers/jwt_auth_engine/passwords_controller.rb
|
|
85
|
+
- app/controllers/jwt_auth_engine/ping_controller.rb
|
|
86
|
+
- app/controllers/jwt_auth_engine/profiles_controller.rb
|
|
87
|
+
- app/controllers/jwt_auth_engine/registrations_controller.rb
|
|
88
|
+
- app/controllers/jwt_auth_engine/sessions_controller.rb
|
|
89
|
+
- app/controllers/jwt_auth_engine/tokens_controller.rb
|
|
90
|
+
- app/services/jwt_auth_engine/base_service.rb
|
|
91
|
+
- app/services/jwt_auth_engine/change_password_service.rb
|
|
92
|
+
- app/services/jwt_auth_engine/login_service.rb
|
|
93
|
+
- app/services/jwt_auth_engine/refresh_token_service.rb
|
|
94
|
+
- app/services/jwt_auth_engine/signup_service.rb
|
|
95
|
+
- app/services/jwt_auth_engine/token_service.rb
|
|
96
|
+
- config/routes.rb
|
|
97
|
+
- lib/generators/jwt_auth_engine/install/install_generator.rb
|
|
98
|
+
- lib/generators/jwt_auth_engine/install/templates/add_jwt_auth_engine_columns_migration.rb.tt
|
|
99
|
+
- lib/generators/jwt_auth_engine/install/templates/auth_model_concern.rb.tt
|
|
100
|
+
- lib/generators/jwt_auth_engine/install/templates/jwt_auth_engine_initializer.rb.tt
|
|
101
|
+
- lib/jwt_auth_engine.rb
|
|
102
|
+
- lib/jwt_auth_engine/configuration.rb
|
|
103
|
+
- lib/jwt_auth_engine/constants.rb
|
|
104
|
+
- lib/jwt_auth_engine/engine.rb
|
|
105
|
+
- lib/jwt_auth_engine/errors.rb
|
|
106
|
+
- lib/jwt_auth_engine/version.rb
|
|
107
|
+
- sig/jwt_auth_engine.rbs
|
|
108
|
+
homepage: https://github.com/abhiskush/jwt_auth_engine
|
|
109
|
+
licenses:
|
|
110
|
+
- MIT
|
|
111
|
+
metadata:
|
|
112
|
+
allowed_push_host: https://rubygems.org
|
|
113
|
+
homepage_uri: https://github.com/abhiskush/jwt_auth_engine
|
|
114
|
+
source_code_uri: https://github.com/abhiskush/jwt_auth_engine
|
|
115
|
+
changelog_uri: https://github.com/abhiskush/jwt_auth_engine/blob/main/CHANGELOG.md
|
|
116
|
+
bug_tracker_uri: https://github.com/abhiskush/jwt_auth_engine/issues
|
|
117
|
+
rubygems_mfa_required: 'true'
|
|
118
|
+
post_install_message:
|
|
119
|
+
rdoc_options: []
|
|
120
|
+
require_paths:
|
|
121
|
+
- lib
|
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
|
+
requirements:
|
|
124
|
+
- - ">="
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: 3.0.0
|
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
requirements: []
|
|
133
|
+
rubygems_version: 3.5.23
|
|
134
|
+
signing_key:
|
|
135
|
+
specification_version: 4
|
|
136
|
+
summary: A Rails engine gem for JWT-based authentication using BCrypt.
|
|
137
|
+
test_files: []
|