lockie 0.2.14 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2fbe268cb9149d19e62b0e508449c3c805f735162911db10c1e14469ce4598ea
4
- data.tar.gz: 8192dc9af5ca2a778be648bbe364b1ed005a8fd5b13edf966662056acb387877
3
+ metadata.gz: 5ee73ebd0d83d510942864ae11dad538c578fa4b396fad352d6c4f1602fdfbd5
4
+ data.tar.gz: 5fce20025be471f55631caa7d6d9ce874b640b838e517662e0d26acd6f576e42
5
5
  SHA512:
6
- metadata.gz: 8820f4ffe9b93814b235eab3faea5f110c2d13d5f339a62e1b22476ceb8cb4c43bd5907f1e1b1e04cab6558e05a01a09f2c233100f25b146bfeb87022286506d
7
- data.tar.gz: ab3109f87d1f6204a455c50b38dcf4895e48ca2c205fa2407e839f427e689a7ad1cffdca5cbb074db84bb989713b55f137ef403afab7e17b929b52bd964091d2
6
+ metadata.gz: 5005acb3551a23b03aa7e6e1a87e0224c054fde2e1768cf84c3d278064ab1f9ff8b525d0a4c209dfa48cf11340b74935e13a14cdaa04f7b12c6b69c7c27a71b8
7
+ data.tar.gz: a002a2bd09c46b611a0d1ac544f65c74dd93bc69c632da534d12cc3e869e93cc73bd10d1056645d6c00c63ad18474eaebc759125cc2e4331a7aa87df08449b12
data/README.md CHANGED
@@ -9,7 +9,7 @@ A drop-in, none assuming warden based Password and JWT authentication for Rails
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'lockie', '~> 0.2.14'
12
+ gem 'lockie', '~> 0.3.3'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -21,6 +21,7 @@ module Lockie
21
21
  attr_accessor :callback_url
22
22
  attr_accessor :scopes
23
23
  attr_accessor :serializer_to_session, :serializer_from_session
24
+ attr_accessor :session_timeout
24
25
 
25
26
  def initialize
26
27
  @model_name = "User"
@@ -32,6 +33,7 @@ module Lockie
32
33
  @scopes = []
33
34
  @serializer_to_session = nil
34
35
  @serializer_from_session = nil
36
+ @session_timeout = 3.hours
35
37
  end
36
38
  end
37
39
 
@@ -30,6 +30,7 @@ module Lockie
30
30
  def authenticated?(*args)
31
31
  warden.authenticated?(*args)
32
32
  end
33
+
33
34
  alias logged_in? authenticated?
34
35
 
35
36
  def logout(*args)
@@ -38,5 +39,6 @@ module Lockie
38
39
  end
39
40
 
40
41
  end
42
+
41
43
  end
42
44
  end
@@ -34,9 +34,12 @@ module Lockie
34
34
  flash[type] = message if message
35
35
  self.status = 302
36
36
  if Lockie.config.callback_url
37
- callback_url = request.base_url + request.original_fullpath
38
37
  uri = URI(warden_options[:unauthenticated_path] || Lockie.config.unauthenticated_path)
39
- uri.query = (uri.query.to_s.split("&") << "callback_url=#{ callback_url }").join("&")
38
+ # only add callback_url if original path is not the same with login path
39
+ unless request.original_fullpath == uri.path
40
+ callback_url = request.base_url + request.original_fullpath
41
+ uri.query = (uri.query.to_s.split("&") << "callback_url=#{ callback_url }").join("&")
42
+ end
40
43
  redirect_to uri.to_s
41
44
  else
42
45
  redirect_to Lockie.config.unauthenticated_path
@@ -8,19 +8,33 @@ module Lockie
8
8
  manager.failure_app = Lockie::FailureApp
9
9
 
10
10
  if Lockie.config.serialize_session
11
- serializer_to_session = Lockie.config.serializer_to_session || proc { |u| u.email }
11
+ serializer_to_session = Lockie.config.serializer_to_session || proc { |u| [u.class.name, u.id] }
12
12
  manager.serialize_into_session(&serializer_to_session)
13
- serializer_from_session = Lockie.config.serializer_from_session || proc { |email| Lockie.config.model_name.classify.constantize.find_by_email(email) }
13
+ serializer_from_session = Lockie.config.serializer_from_session || proc { |s| s.first.constantize.find(s.last) }
14
14
  manager.serialize_from_session(&serializer_from_session)
15
15
  end
16
16
 
17
17
  Lockie.config.scopes.each do |scope|
18
- manager.scope_defaults *scope
18
+ manager.scope_defaults(*scope)
19
19
  end
20
20
 
21
21
  end
22
22
  end
23
23
  end
24
24
 
25
+ Warden::Manager.after_authentication do |record, warden, options|
26
+ session_key = "warden.uls-#{record.class.name.underscore}-#{record.id}"
27
+ warden.request.session[session_key] = (Time.now + Lockie.config.session_timeout).to_s
28
+ end
29
+
25
30
  Warden::Manager.after_set_user do |record, warden, options|
31
+ session_key = "warden.uls-#{record.class.name.underscore}-#{record.id}"
32
+ last_session_access = warden.request.session[session_key]
33
+
34
+ if last_session_access && Time.parse(last_session_access) < Time.now
35
+ # session expired
36
+ warden.logout
37
+ end
38
+
39
+ warden.request.session[session_key] = Time.now + Lockie.config.session_timeout
26
40
  end
@@ -1,3 +1,3 @@
1
1
  module Lockie
2
- VERSION = '0.2.14'
2
+ VERSION = '0.3.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melvin Sembrano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-20 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -135,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.7.7
138
+ rubygems_version: 3.0.8
140
139
  signing_key:
141
140
  specification_version: 4
142
141
  summary: Drop in password and JWT token authentication for Ruby on Rails