lockie 0.2.13 → 0.3.3

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: d202a04abf27c03afdd6a0de047d4f40789aeaa9ac42927762fa2ad83029d491
4
- data.tar.gz: ff63303453740b70b984b8adab5cf0bcf987e1bc9ee839d9baae25e665f635c0
3
+ metadata.gz: 4d9b6208ff552c48fcd48bf7dac345af06b688c598d8007248aa0b1801959b99
4
+ data.tar.gz: b597f952ff77c9881ef7e4ab6f8a79f424c3265c3d84e673e0a1743725d5b733
5
5
  SHA512:
6
- metadata.gz: 681a8fe65fc80668b554ea412a7278d86207db37278e044832b056003ff3cb7ab17ddcb073481d3c23c9efd4d3c30fc9ce469d602cc337eee8c167ea7d6d62ab
7
- data.tar.gz: 195ae8d4d102b15017c6c56a343a69799361a8b643da26c48be9f587fd72fdb6415c0bad4851f1904c3e3595d9e915f2a0ca2131c93ef1e33fe5ef94b3aaa879
6
+ metadata.gz: 7878cb4bfe31f051b5f063c4467b52bde16494f8dde23661012414b5562b3dd65dfc20d005210582a0854fff51240b64faee18669b5355e67b4e27ebc4e40818
7
+ data.tar.gz: f7967811725b81454729fdb33711e69441e843efe65affb96dca44d266add3c7897f52c746898f163affa1061580d3aeb183d1c2b6409a4983f8ab82c30aabe8
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.3'
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.13'
2
+ VERSION = '0.3.3'
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.13
4
+ version: 0.3.3
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-03-06 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