tinytokenauth-rails 0.1.6 → 0.1.7
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/Gemfile.lock +1 -1
- data/lib/tinytokenauth/authorizable.rb +18 -16
- data/lib/tinytokenauth/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9b10e6633d4606de4ec2969019871de80021a50126afac2c928abcb69ecf403
|
4
|
+
data.tar.gz: ab5f071a30e1408bc4467dc797607962f1b68d035954287aae753b959b4aa479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90e3dc70c6e8d28265862f23cdb9eb8581f6220fa13ed4d1428118227cefb1131e7e2ed5083666ba8e0d070ae48ef506eb343ab2b40d355c76c8a1d5234df41
|
7
|
+
data.tar.gz: 57be5affdbfbf2b5205077627c59115c1f0bf756ac12df2d3fe82cd89bd37acef5d7e868519ae0ea9f1e39e91336a27d1575e58f8e9b048fceafa5a8b87e7db9
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
module Tinytokenauth
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
class << self
|
4
|
+
def configuration
|
5
|
+
@configuration ||= Configuration.new
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
def configure
|
9
|
+
yield(configuration)
|
12
10
|
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Authorizable
|
14
|
+
|
13
15
|
|
14
16
|
def authorize_with_header
|
15
17
|
token = ''
|
@@ -19,7 +21,7 @@ module Tinytokenauth
|
|
19
21
|
begin
|
20
22
|
@decoded = JsonWebToken.decode(token)
|
21
23
|
# @current_user = User.find(@decoded[:user_id])
|
22
|
-
@current_user =
|
24
|
+
@current_user = Tinytokenauth.configuration.user_class.send 'find', @decoded[:user_id]
|
23
25
|
rescue ActiveRecord::RecordNotFound => e
|
24
26
|
render json: { errors: e.message }, status: :unauthorized
|
25
27
|
rescue JWT::DecodeError => e
|
@@ -60,15 +62,15 @@ module Tinytokenauth
|
|
60
62
|
# end
|
61
63
|
|
62
64
|
def require_current_user(&block)
|
63
|
-
token = cookies[
|
65
|
+
token = cookies[Tinytokenauth.configuration.cookie_name]
|
64
66
|
# p "token from cookie: #{token}"
|
65
67
|
begin
|
66
68
|
@decoded = JsonWebToken.decode(token)
|
67
69
|
# @current_user = User.find(@decoded[:user_id])
|
68
|
-
@current_user =
|
70
|
+
@current_user = Tinytokenauth.configuration.user_class.send 'find', @decoded[:user_id]
|
69
71
|
@exp = @decoded[:exp]
|
70
|
-
if
|
71
|
-
@exp <
|
72
|
+
if Tinytokenauth.configuration.token_auto_renew_hours &&
|
73
|
+
@exp < Tinytokenauth.configuration.token_auto_renew_hours.hours.from_now.to_i
|
72
74
|
sign_in @current_user
|
73
75
|
end
|
74
76
|
rescue ActiveRecord::RecordNotFound, JWT::DecodeError => e
|
@@ -115,9 +117,9 @@ module Tinytokenauth
|
|
115
117
|
def sign_in(user)
|
116
118
|
@current_user = user
|
117
119
|
jwt = JsonWebToken.encode(user_id: user.id,
|
118
|
-
exp:
|
119
|
-
secret:
|
120
|
-
cookies[
|
120
|
+
exp: Tinytokenauth.configuration.token_validity_hours.hours.from_now,
|
121
|
+
secret: Tinytokenauth.configuration.token_secret)
|
122
|
+
cookies[Tinytokenauth.configuration.cookie_name] = jwt
|
121
123
|
end
|
122
124
|
|
123
125
|
def current_user
|