lockie 0.2.12 → 0.3.1

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: dac3acfaeeeb25086363798a25f30236b2aa4421c592ec2a9a19f4d6b67a4f85
4
- data.tar.gz: 96ca18b9450ad04e852ed8ecea300857aa62473bf628e720d33e5d56ddf3017e
3
+ metadata.gz: 4891f7485ad02efb026b823bc53c1975f05661eca97414310fdf89a93305188d
4
+ data.tar.gz: 4ba661f6c8e3e40415695f9fecd2fe7fb7e3d9d2ef5542af7420792575c7d399
5
5
  SHA512:
6
- metadata.gz: 30689a81b8ebc05008d54b60b570ac85eae14913b2d6e89878324fffe1d27ed8e7bcf83f992ca3c22e44800603d7d58eafb26b66d595e4853fcb5318a90fee48
7
- data.tar.gz: 86040b9b8a51c3e51ff30ccf258680e8a580edf2f79ebc32cefc0cfa6de5e86077b4fa2557ab046dfb65709aff1368b5aedea2219cbcbdd0ebd3c27a3ae47f44
6
+ metadata.gz: a1d92c0e6f02c98dcd46adc5fdb9559e9593f7c6f90f513eca1569d00ea77fa14c6b58afa41470806477b57bb786b191cd9e29d5fd3e9b1dbdd351bc46186f16
7
+ data.tar.gz: 70ae39adb0997816279aac2880cdc274dd1b2e1e253ac4008aa7bcd0cd50348fc1a6ac2731c9714c96a9a857b0a04e5f62ddfb976052393f739e464a2960a5b6
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.11'
12
+ gem 'lockie', '~> 0.3.1'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -89,7 +89,8 @@ Lockie.configure do |c|
89
89
  # set custom scopes
90
90
  c.scopes = [
91
91
  [:api, { store: false, strategies: [:jwt]}],
92
- [:web, { store: true, strategies: [:email_password]}]
92
+ [:web, { store: true, strategies: [:email_password]}],
93
+ [:admin, { store: true, strategies: [:email_password], unauthenticated_path: "/login-admin" }]
93
94
  ]
94
95
  end
95
96
  ```
@@ -101,12 +102,12 @@ Using `Warden::Test::Helpers` https://github.com/wardencommunity/warden/wiki/tes
101
102
  ```
102
103
  include Warden::Test::Helpers
103
104
 
104
- before do
105
+ setup do
105
106
  @user = users(:one)
106
107
  login_as @user
107
108
 
108
109
  end
109
- after { Warden.test_reset! }
110
+ teardown { Warden.test_reset! }
110
111
  ```
111
112
 
112
113
  ### Testing JSON Api with token
@@ -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
@@ -35,7 +35,7 @@ module Lockie
35
35
  self.status = 302
36
36
  if Lockie.config.callback_url
37
37
  callback_url = request.base_url + request.original_fullpath
38
- uri = URI(Lockie.config.unauthenticated_path)
38
+ uri = URI(warden_options[:unauthenticated_path] || Lockie.config.unauthenticated_path)
39
39
  uri.query = (uri.query.to_s.split("&") << "callback_url=#{ callback_url }").join("&")
40
40
  redirect_to uri.to_s
41
41
  else
@@ -56,7 +56,7 @@ module Lockie
56
56
  end
57
57
 
58
58
  def warden
59
- env['warden']
59
+ request.env['warden']
60
60
  end
61
61
 
62
62
  end
@@ -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.12'
2
+ VERSION = '0.3.1'
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.12
4
+ version: 0.3.1
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-02-25 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -81,19 +81,19 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: 3.1.7
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: byebug
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.12'
89
+ version: 11.1.3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.12'
96
+ version: 11.1.3
97
97
  description: Drop in password and JWT token authentication for Ruby on Rails
98
98
  email:
99
99
  - melvinsembrano@gmail.com
@@ -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