tinytokenauth-rails 0.1.0 → 0.1.1
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 +137 -1
- data/lib/tinytokenauth/authorizable.rb +133 -0
- data/lib/tinytokenauth/configuration.rb +6 -0
- data/lib/tinytokenauth/engine.rb +10 -0
- data/lib/tinytokenauth/{rails/version.rb → version.rb} +1 -3
- data/lib/tinytokenauth/{rails/view_helpers.rb → view_helpers.rb} +0 -2
- data/lib/tinytokenauth.rb +16 -0
- metadata +21 -7
- data/lib/tinytokenauth/rails/authorizable.rb +0 -134
- data/lib/tinytokenauth/rails/configuration.rb +0 -7
- data/lib/tinytokenauth/rails/railtie.rb +0 -11
- data/lib/tinytokenauth/rails.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62e5b134761c6b6009408bf044d89af8f97a343a35edb30871c98479568a0cc2
|
4
|
+
data.tar.gz: 88891f8ee0df8a324869ea9e3a429f76a35bde3f073cef8aa93f51013a0203b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00e6b497c92575be98be6122612cc01d61c9804d1c940c94785e3295cd77fa16902df4bb3014f92622e2ac72c5384512c24248a881d9172bd5252db5456ad5f4
|
7
|
+
data.tar.gz: 5af3702edf28bd7b5115a6bbc178239ccda067ab8ff7635039c2385baee4cd28333fe144a65b86316864c94239fd43322dce4a984feb512c480a7594f3d854e4
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,154 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tinytokenauth-rails (0.1.
|
4
|
+
tinytokenauth-rails (0.1.1)
|
5
5
|
bcrypt (~> 3.1)
|
6
6
|
jwt (~> 2.7)
|
7
|
+
rails (>= 6.0)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
actioncable (7.0.4.3)
|
13
|
+
actionpack (= 7.0.4.3)
|
14
|
+
activesupport (= 7.0.4.3)
|
15
|
+
nio4r (~> 2.0)
|
16
|
+
websocket-driver (>= 0.6.1)
|
17
|
+
actionmailbox (7.0.4.3)
|
18
|
+
actionpack (= 7.0.4.3)
|
19
|
+
activejob (= 7.0.4.3)
|
20
|
+
activerecord (= 7.0.4.3)
|
21
|
+
activestorage (= 7.0.4.3)
|
22
|
+
activesupport (= 7.0.4.3)
|
23
|
+
mail (>= 2.7.1)
|
24
|
+
net-imap
|
25
|
+
net-pop
|
26
|
+
net-smtp
|
27
|
+
actionmailer (7.0.4.3)
|
28
|
+
actionpack (= 7.0.4.3)
|
29
|
+
actionview (= 7.0.4.3)
|
30
|
+
activejob (= 7.0.4.3)
|
31
|
+
activesupport (= 7.0.4.3)
|
32
|
+
mail (~> 2.5, >= 2.5.4)
|
33
|
+
net-imap
|
34
|
+
net-pop
|
35
|
+
net-smtp
|
36
|
+
rails-dom-testing (~> 2.0)
|
37
|
+
actionpack (7.0.4.3)
|
38
|
+
actionview (= 7.0.4.3)
|
39
|
+
activesupport (= 7.0.4.3)
|
40
|
+
rack (~> 2.0, >= 2.2.0)
|
41
|
+
rack-test (>= 0.6.3)
|
42
|
+
rails-dom-testing (~> 2.0)
|
43
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
44
|
+
actiontext (7.0.4.3)
|
45
|
+
actionpack (= 7.0.4.3)
|
46
|
+
activerecord (= 7.0.4.3)
|
47
|
+
activestorage (= 7.0.4.3)
|
48
|
+
activesupport (= 7.0.4.3)
|
49
|
+
globalid (>= 0.6.0)
|
50
|
+
nokogiri (>= 1.8.5)
|
51
|
+
actionview (7.0.4.3)
|
52
|
+
activesupport (= 7.0.4.3)
|
53
|
+
builder (~> 3.1)
|
54
|
+
erubi (~> 1.4)
|
55
|
+
rails-dom-testing (~> 2.0)
|
56
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
57
|
+
activejob (7.0.4.3)
|
58
|
+
activesupport (= 7.0.4.3)
|
59
|
+
globalid (>= 0.3.6)
|
60
|
+
activemodel (7.0.4.3)
|
61
|
+
activesupport (= 7.0.4.3)
|
62
|
+
activerecord (7.0.4.3)
|
63
|
+
activemodel (= 7.0.4.3)
|
64
|
+
activesupport (= 7.0.4.3)
|
65
|
+
activestorage (7.0.4.3)
|
66
|
+
actionpack (= 7.0.4.3)
|
67
|
+
activejob (= 7.0.4.3)
|
68
|
+
activerecord (= 7.0.4.3)
|
69
|
+
activesupport (= 7.0.4.3)
|
70
|
+
marcel (~> 1.0)
|
71
|
+
mini_mime (>= 1.1.0)
|
72
|
+
activesupport (7.0.4.3)
|
73
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
74
|
+
i18n (>= 1.6, < 2)
|
75
|
+
minitest (>= 5.1)
|
76
|
+
tzinfo (~> 2.0)
|
11
77
|
ast (2.4.2)
|
12
78
|
base64 (0.1.1)
|
13
79
|
bcrypt (3.1.19)
|
80
|
+
builder (3.2.4)
|
81
|
+
concurrent-ruby (1.2.2)
|
82
|
+
crass (1.0.6)
|
83
|
+
date (3.3.3)
|
14
84
|
diff-lcs (1.5.0)
|
85
|
+
erubi (1.12.0)
|
86
|
+
globalid (1.1.0)
|
87
|
+
activesupport (>= 5.0)
|
88
|
+
i18n (1.13.0)
|
89
|
+
concurrent-ruby (~> 1.0)
|
15
90
|
json (2.6.3)
|
16
91
|
jwt (2.7.1)
|
17
92
|
language_server-protocol (3.17.0.3)
|
18
93
|
lint_roller (1.1.0)
|
94
|
+
loofah (2.21.2)
|
95
|
+
crass (~> 1.0.2)
|
96
|
+
nokogiri (>= 1.12.0)
|
97
|
+
mail (2.8.1)
|
98
|
+
mini_mime (>= 0.1.1)
|
99
|
+
net-imap
|
100
|
+
net-pop
|
101
|
+
net-smtp
|
102
|
+
marcel (1.0.2)
|
103
|
+
method_source (1.0.0)
|
104
|
+
mini_mime (1.1.2)
|
105
|
+
minitest (5.18.0)
|
106
|
+
net-imap (0.3.4)
|
107
|
+
date
|
108
|
+
net-protocol
|
109
|
+
net-pop (0.1.2)
|
110
|
+
net-protocol
|
111
|
+
net-protocol (0.2.1)
|
112
|
+
timeout
|
113
|
+
net-smtp (0.3.3)
|
114
|
+
net-protocol
|
115
|
+
nio4r (2.5.9)
|
116
|
+
nokogiri (1.14.4-arm64-darwin)
|
117
|
+
racc (~> 1.4)
|
19
118
|
parallel (1.23.0)
|
20
119
|
parser (3.2.2.4)
|
21
120
|
ast (~> 2.4.1)
|
22
121
|
racc
|
23
122
|
racc (1.7.1)
|
123
|
+
rack (2.2.7)
|
124
|
+
rack-test (2.1.0)
|
125
|
+
rack (>= 1.3)
|
126
|
+
rails (7.0.4.3)
|
127
|
+
actioncable (= 7.0.4.3)
|
128
|
+
actionmailbox (= 7.0.4.3)
|
129
|
+
actionmailer (= 7.0.4.3)
|
130
|
+
actionpack (= 7.0.4.3)
|
131
|
+
actiontext (= 7.0.4.3)
|
132
|
+
actionview (= 7.0.4.3)
|
133
|
+
activejob (= 7.0.4.3)
|
134
|
+
activemodel (= 7.0.4.3)
|
135
|
+
activerecord (= 7.0.4.3)
|
136
|
+
activestorage (= 7.0.4.3)
|
137
|
+
activesupport (= 7.0.4.3)
|
138
|
+
bundler (>= 1.15.0)
|
139
|
+
railties (= 7.0.4.3)
|
140
|
+
rails-dom-testing (2.0.3)
|
141
|
+
activesupport (>= 4.2.0)
|
142
|
+
nokogiri (>= 1.6)
|
143
|
+
rails-html-sanitizer (1.5.0)
|
144
|
+
loofah (~> 2.19, >= 2.19.1)
|
145
|
+
railties (7.0.4.3)
|
146
|
+
actionpack (= 7.0.4.3)
|
147
|
+
activesupport (= 7.0.4.3)
|
148
|
+
method_source
|
149
|
+
rake (>= 12.2)
|
150
|
+
thor (~> 1.0)
|
151
|
+
zeitwerk (~> 2.5)
|
24
152
|
rainbow (3.1.1)
|
25
153
|
rake (13.0.6)
|
26
154
|
regexp_parser (2.8.2)
|
@@ -68,7 +196,15 @@ GEM
|
|
68
196
|
standard-performance (1.2.1)
|
69
197
|
lint_roller (~> 1.1)
|
70
198
|
rubocop-performance (~> 1.19.1)
|
199
|
+
thor (1.2.1)
|
200
|
+
timeout (0.3.2)
|
201
|
+
tzinfo (2.0.6)
|
202
|
+
concurrent-ruby (~> 1.0)
|
71
203
|
unicode-display_width (2.5.0)
|
204
|
+
websocket-driver (0.7.5)
|
205
|
+
websocket-extensions (>= 0.1.0)
|
206
|
+
websocket-extensions (0.1.5)
|
207
|
+
zeitwerk (2.6.11)
|
72
208
|
|
73
209
|
PLATFORMS
|
74
210
|
arm64-darwin-22
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Tinytokenauth
|
2
|
+
|
3
|
+
module Authorizable
|
4
|
+
# class Configuration
|
5
|
+
# attr_accessor :token_duration
|
6
|
+
# end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def configuration
|
10
|
+
@configuration ||= Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def authorize_with_header(klass = User)
|
19
|
+
token = ''
|
20
|
+
header = request.headers['Authorization']
|
21
|
+
token = header.split(' ').last if header
|
22
|
+
# p "token from header: #{token}"
|
23
|
+
|
24
|
+
begin
|
25
|
+
@decoded = JsonWebToken.decode(token)
|
26
|
+
# @current_user = User.find(@decoded[:user_id])
|
27
|
+
@current_user = klass.send 'find', @decoded[:user_id]
|
28
|
+
rescue ActiveRecord::RecordNotFound => e
|
29
|
+
render json: { errors: e.message }, status: :unauthorized
|
30
|
+
rescue JWT::DecodeError => e
|
31
|
+
render json: { errors: e.message }, status: :unauthorized
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Tinytokenauth.configure do |config|
|
36
|
+
# config.token_duration = 24.hours
|
37
|
+
# end
|
38
|
+
|
39
|
+
def require_current_user(klass = User)
|
40
|
+
token = cookies['klap-auth']
|
41
|
+
# p "token from cookie: #{token}"
|
42
|
+
|
43
|
+
begin
|
44
|
+
@decoded = JsonWebToken.decode(token)
|
45
|
+
# @current_user = User.find(@decoded[:user_id])
|
46
|
+
@current_user = klass.send 'find', @decoded[:user_id]
|
47
|
+
@exp = @decoded[:exp]
|
48
|
+
# if @exp < 24.hours.from_now.to_i # Always refresh token
|
49
|
+
if @exp < 4.hours.from_now.to_i # Always refresh token
|
50
|
+
sign_in @current_user
|
51
|
+
end
|
52
|
+
rescue ActiveRecord::RecordNotFound => e
|
53
|
+
# TODO: evaluate if we should always forward
|
54
|
+
redirect_to new_session_path(forward_to: request.path), notice: "Please sign in again" #, status: :unauthorized
|
55
|
+
rescue JWT::DecodeError => e
|
56
|
+
# TODO: evaluate if we should always forward
|
57
|
+
# render json: { errors: e.message }, status: :unauthorized
|
58
|
+
redirect_to new_session_path(forward_to: request.path), notice: "Please sign in again" #, status: :unauthorized
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# def require_current_user2(klass = User, &block)
|
63
|
+
# current_user = set_current_user(klass)
|
64
|
+
# if block_given? && current_user.nil?
|
65
|
+
# block.call
|
66
|
+
# else
|
67
|
+
# raise MissingArgumentError
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
|
71
|
+
def require_current_user2(klass = User, &block)
|
72
|
+
token = cookies['klap-auth']
|
73
|
+
# p "token from cookie: #{token}"
|
74
|
+
begin
|
75
|
+
@decoded = JsonWebToken.decode(token)
|
76
|
+
# @current_user = User.find(@decoded[:user_id])
|
77
|
+
@current_user = klass.send 'find', @decoded[:user_id]
|
78
|
+
@exp = @decoded[:exp]
|
79
|
+
# if @exp < 24.hours.from_now.to_i # Always refresh token
|
80
|
+
if @exp < 4.hours.from_now.to_i # Always refresh token
|
81
|
+
sign_in @current_user
|
82
|
+
end
|
83
|
+
rescue ActiveRecord::RecordNotFound, JWT::DecodeError => e
|
84
|
+
if block_given? && current_user.nil?
|
85
|
+
block.call
|
86
|
+
else
|
87
|
+
raise e
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def set_current_user(klass = User)
|
93
|
+
token = cookies['klap-auth']
|
94
|
+
begin
|
95
|
+
@decoded = JsonWebToken.decode(token)
|
96
|
+
# @current_user = User.find(@decoded[:user_id])
|
97
|
+
@current_user = klass.send 'find', @decoded[:user_id]
|
98
|
+
@exp = @decoded[:exp]
|
99
|
+
# if @exp < 24.hours.from_now.to_i # Always refresh token
|
100
|
+
if @exp < 4.hours.from_now.to_i # Always refresh token
|
101
|
+
# token = JsonWebToken.encode(user_id: @current_user.id)
|
102
|
+
# cookies['klap-auth'] = token
|
103
|
+
sign_in @current_user
|
104
|
+
end
|
105
|
+
rescue ActiveRecord::RecordNotFound
|
106
|
+
# Ignored
|
107
|
+
rescue JWT::DecodeError
|
108
|
+
# Ignored
|
109
|
+
end
|
110
|
+
@current_user
|
111
|
+
end
|
112
|
+
|
113
|
+
def set_current_user2(klass = User)
|
114
|
+
begin
|
115
|
+
require_current_user2(klass)
|
116
|
+
rescue ActiveRecord::RecordNotFound
|
117
|
+
# Ignored
|
118
|
+
rescue JWT::DecodeError
|
119
|
+
# Ignored
|
120
|
+
end
|
121
|
+
@current_user
|
122
|
+
end
|
123
|
+
|
124
|
+
def sign_in(user)
|
125
|
+
@current_user = user
|
126
|
+
cookies['klap-auth'] = JsonWebToken.encode(user_id: user.id)
|
127
|
+
end
|
128
|
+
|
129
|
+
def current_user
|
130
|
+
@current_user
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinytokenauth
|
4
|
+
require_relative "tinytokenauth/version"
|
5
|
+
require_relative "tinytokenauth/engine"
|
6
|
+
require_relative "tinytokenauth/authorizable"
|
7
|
+
require_relative "tinytokenauth/view_helpers"
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
# module Tinytokenauth
|
12
|
+
# module Rails
|
13
|
+
# class Error < StandardError; end
|
14
|
+
# # Your code goes here...
|
15
|
+
# end
|
16
|
+
# end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tinytokenauth-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kim Laplume
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: jwt
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,12 +67,12 @@ files:
|
|
53
67
|
- LICENSE.txt
|
54
68
|
- README.md
|
55
69
|
- Rakefile
|
56
|
-
- lib/tinytokenauth
|
57
|
-
- lib/tinytokenauth/
|
58
|
-
- lib/tinytokenauth/
|
59
|
-
- lib/tinytokenauth/
|
60
|
-
- lib/tinytokenauth/
|
61
|
-
- lib/tinytokenauth/
|
70
|
+
- lib/tinytokenauth.rb
|
71
|
+
- lib/tinytokenauth/authorizable.rb
|
72
|
+
- lib/tinytokenauth/configuration.rb
|
73
|
+
- lib/tinytokenauth/engine.rb
|
74
|
+
- lib/tinytokenauth/version.rb
|
75
|
+
- lib/tinytokenauth/view_helpers.rb
|
62
76
|
- sig/tinytokenauth/rails.rbs
|
63
77
|
homepage: https://github.com/1klap/tinytokenauth-rails
|
64
78
|
licenses:
|
@@ -1,134 +0,0 @@
|
|
1
|
-
module Tinytokenauth
|
2
|
-
module Rails
|
3
|
-
module Authorizable
|
4
|
-
# class Configuration
|
5
|
-
# attr_accessor :token_duration
|
6
|
-
# end
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def configuration
|
10
|
-
@configuration ||= Configuration.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def configure
|
14
|
-
yield(configuration)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def authorize_with_header(klass = User)
|
19
|
-
token = ''
|
20
|
-
header = request.headers['Authorization']
|
21
|
-
token = header.split(' ').last if header
|
22
|
-
# p "token from header: #{token}"
|
23
|
-
|
24
|
-
begin
|
25
|
-
@decoded = JsonWebToken.decode(token)
|
26
|
-
# @current_user = User.find(@decoded[:user_id])
|
27
|
-
@current_user = klass.send 'find', @decoded[:user_id]
|
28
|
-
rescue ActiveRecord::RecordNotFound => e
|
29
|
-
render json: { errors: e.message }, status: :unauthorized
|
30
|
-
rescue JWT::DecodeError => e
|
31
|
-
render json: { errors: e.message }, status: :unauthorized
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Tinytokenauth.configure do |config|
|
36
|
-
# config.token_duration = 24.hours
|
37
|
-
# end
|
38
|
-
|
39
|
-
def require_current_user(klass = User)
|
40
|
-
token = cookies['klap-auth']
|
41
|
-
# p "token from cookie: #{token}"
|
42
|
-
|
43
|
-
begin
|
44
|
-
@decoded = JsonWebToken.decode(token)
|
45
|
-
# @current_user = User.find(@decoded[:user_id])
|
46
|
-
@current_user = klass.send 'find', @decoded[:user_id]
|
47
|
-
@exp = @decoded[:exp]
|
48
|
-
#if @exp < 24.hours.from_now.to_i # Always refresh token
|
49
|
-
if @exp < 4.hours.from_now.to_i # Always refresh token
|
50
|
-
sign_in @current_user
|
51
|
-
end
|
52
|
-
rescue ActiveRecord::RecordNotFound => e
|
53
|
-
# TODO: evaluate if we should always forward
|
54
|
-
redirect_to new_session_path(forward_to: request.path), notice: "Please sign in again" #, status: :unauthorized
|
55
|
-
rescue JWT::DecodeError => e
|
56
|
-
# TODO: evaluate if we should always forward
|
57
|
-
# render json: { errors: e.message }, status: :unauthorized
|
58
|
-
redirect_to new_session_path(forward_to: request.path), notice: "Please sign in again" #, status: :unauthorized
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# def require_current_user2(klass = User, &block)
|
63
|
-
# current_user = set_current_user(klass)
|
64
|
-
# if block_given? && current_user.nil?
|
65
|
-
# block.call
|
66
|
-
# else
|
67
|
-
# raise MissingArgumentError
|
68
|
-
# end
|
69
|
-
# end
|
70
|
-
|
71
|
-
def require_current_user2(klass = User, &block)
|
72
|
-
token = cookies['klap-auth']
|
73
|
-
# p "token from cookie: #{token}"
|
74
|
-
begin
|
75
|
-
@decoded = JsonWebToken.decode(token)
|
76
|
-
# @current_user = User.find(@decoded[:user_id])
|
77
|
-
@current_user = klass.send 'find', @decoded[:user_id]
|
78
|
-
@exp = @decoded[:exp]
|
79
|
-
#if @exp < 24.hours.from_now.to_i # Always refresh token
|
80
|
-
if @exp < 4.hours.from_now.to_i # Always refresh token
|
81
|
-
sign_in @current_user
|
82
|
-
end
|
83
|
-
rescue ActiveRecord::RecordNotFound, JWT::DecodeError => e
|
84
|
-
if block_given? && current_user.nil?
|
85
|
-
block.call
|
86
|
-
else
|
87
|
-
raise e
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def set_current_user(klass = User)
|
93
|
-
token = cookies['klap-auth']
|
94
|
-
begin
|
95
|
-
@decoded = JsonWebToken.decode(token)
|
96
|
-
# @current_user = User.find(@decoded[:user_id])
|
97
|
-
@current_user = klass.send 'find', @decoded[:user_id]
|
98
|
-
@exp = @decoded[:exp]
|
99
|
-
#if @exp < 24.hours.from_now.to_i # Always refresh token
|
100
|
-
if @exp < 4.hours.from_now.to_i # Always refresh token
|
101
|
-
# token = JsonWebToken.encode(user_id: @current_user.id)
|
102
|
-
# cookies['klap-auth'] = token
|
103
|
-
sign_in @current_user
|
104
|
-
end
|
105
|
-
rescue ActiveRecord::RecordNotFound
|
106
|
-
# Ignored
|
107
|
-
rescue JWT::DecodeError
|
108
|
-
# Ignored
|
109
|
-
end
|
110
|
-
@current_user
|
111
|
-
end
|
112
|
-
|
113
|
-
def set_current_user2(klass = User)
|
114
|
-
begin
|
115
|
-
require_current_user2(klass)
|
116
|
-
rescue ActiveRecord::RecordNotFound
|
117
|
-
# Ignored
|
118
|
-
rescue JWT::DecodeError
|
119
|
-
# Ignored
|
120
|
-
end
|
121
|
-
@current_user
|
122
|
-
end
|
123
|
-
|
124
|
-
def sign_in(user)
|
125
|
-
@current_user = user
|
126
|
-
cookies['klap-auth'] = JsonWebToken.encode(user_id: user.id)
|
127
|
-
end
|
128
|
-
|
129
|
-
def current_user
|
130
|
-
@current_user
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
data/lib/tinytokenauth/rails.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "rails/version"
|
4
|
-
|
5
|
-
require_relative "rails/authorizable"
|
6
|
-
require_relative "rails/railtie"
|
7
|
-
require_relative "rails/view_helpers"
|
8
|
-
|
9
|
-
# module Tinytokenauth
|
10
|
-
# module Rails
|
11
|
-
# class Error < StandardError; end
|
12
|
-
# # Your code goes here...
|
13
|
-
# end
|
14
|
-
# end
|