jwtauth 0.2.0 → 0.2.2
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 +4 -4
- data/lib/jwtauth.rb +53 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d5f272e7575f762d4249ca524c742b6c737d126
|
4
|
+
data.tar.gz: 626ba9c3b0cd32daabd059013f3303bce25cc95e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1884270b7293ccd219204644b7a6c67f6fb4100c99337950d159310c203d589fa6ec21809daedef8415e19134f31f9cb885da02fed779a827fc732e05f24857a
|
7
|
+
data.tar.gz: 128693dcae70f5b624dc91a3292cf28e88b9bf8ebdc1dce8a7a98933c2470c67c69a52857f98f4431c0eb648e22dc67c41a8a057c1faff23942fdc9ad7dacced
|
data/lib/jwtauth.rb
CHANGED
@@ -20,6 +20,12 @@ module Jwtauth
|
|
20
20
|
# mattr_accessor :algorithm
|
21
21
|
@@algorithm = 'RS256'
|
22
22
|
|
23
|
+
# Option when used jwtauth
|
24
|
+
@@test_mode = false
|
25
|
+
|
26
|
+
# Save temp current_user
|
27
|
+
@@current_user = nil
|
28
|
+
|
23
29
|
# Default way to set up Jwtauth.
|
24
30
|
# a fresh initializer with all configuration values.
|
25
31
|
def self.setup
|
@@ -58,6 +64,30 @@ module Jwtauth
|
|
58
64
|
@@algorithm = algorithm
|
59
65
|
end
|
60
66
|
|
67
|
+
def self.test_mode
|
68
|
+
@@test_mode
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.test_mode=(test_mode)
|
72
|
+
@@test_mode = test_mode
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.test_mode!
|
76
|
+
@@test_mode = true
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.test_mode?
|
80
|
+
@@test_mode
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.current_user
|
84
|
+
@@current_user
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.current_user=(current_user)
|
88
|
+
@@current_user = current_user
|
89
|
+
end
|
90
|
+
|
61
91
|
# Define abstract class error of when call authservice
|
62
92
|
class AuthorizedError < StandardError; end
|
63
93
|
class SocketError < AuthorizedError; end
|
@@ -100,6 +130,10 @@ module Jwtauth
|
|
100
130
|
module Controller
|
101
131
|
# Authorize user
|
102
132
|
def authorize_user!
|
133
|
+
if Jwtauth.test_mode?
|
134
|
+
return @current_user = Jwtauth.current_user
|
135
|
+
end
|
136
|
+
|
103
137
|
begin
|
104
138
|
res = Jwtauth::Session.getjwt(request)
|
105
139
|
rescue Exception => e
|
@@ -157,4 +191,23 @@ module Jwtauth
|
|
157
191
|
module ClassMethods
|
158
192
|
end
|
159
193
|
end
|
194
|
+
|
195
|
+
module Test
|
196
|
+
module IntegrationHelpers
|
197
|
+
def self.included(base)
|
198
|
+
base.class_eval do
|
199
|
+
setup :setup_integration_for_jwtauth
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def sign_in(resource)
|
204
|
+
Jwtauth.current_user = resource
|
205
|
+
end
|
206
|
+
|
207
|
+
protected
|
208
|
+
def setup_integration_for_jwtauth
|
209
|
+
Jwtauth.test_mode!
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
160
213
|
end
|