lockie 0.2.11 → 0.3.0

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: d9d67632a3d86d2fd043ea263f454fc41db3fec787a8040f7811b1f48955b969
4
- data.tar.gz: b258ee9e61c4603b6b6d24d111673c0f8c26becf7e1f911a6a721a78fbeb459e
3
+ metadata.gz: f263a01d6643e64e44c24073bba5299d2e676bc4ec94e933b8237fcdb504db05
4
+ data.tar.gz: 6c1be8dfb1a8db8140a4722297163dbed092eca4cd14366b77f25b0cf54685f0
5
5
  SHA512:
6
- metadata.gz: 9b4a83888975f7d0bdfdaeec4dd3338ad49fc7fed38005cb1d077c3644a128d5c06e67193b588e36bb2eec204212bab1a86c81ec34f577f12ca374d669ac5c50
7
- data.tar.gz: 691cd919952479cc8e1cc0957c83a876c7d1157b0b04550d0dec408382f0a79a5a52349c7ac00bbe3825233c6187b4d9855e76812b2b527cd0284f32673ea128
6
+ metadata.gz: 616c53926c05e0da9bccb86e1bd01e715f6064793a92ffff47cb851e4611c3df23b5e4e125e1f18d1e8964b6f309b8a0b80619fa6477059fe2dd263409f6922e
7
+ data.tar.gz: 197cc104b9afe2f0f42f5aeb26150c6286fe3aa64fffa61251a58455a0fc525c9d9a496be5dc55f40af64454b3ecdf662f8d52207f6045d965dfe3a179bf3a1b
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.2.14'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -89,11 +89,35 @@ 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
  ```
96
97
 
98
+ ## Testing
99
+
100
+ Using `Warden::Test::Helpers` https://github.com/wardencommunity/warden/wiki/testing testing is simple and straight forward
101
+
102
+ ```
103
+ include Warden::Test::Helpers
104
+
105
+ setup do
106
+ @user = users(:one)
107
+ login_as @user
108
+
109
+ end
110
+ teardown { Warden.test_reset! }
111
+ ```
112
+
113
+ ### Testing JSON Api with token
114
+
115
+ ```
116
+ get articles_url(format: :json), headers: {
117
+ Authorization: "Bearer #{ @user.create_token }"
118
+ }
119
+ ```
120
+
97
121
  ## Contributing
98
122
  Contribution directions go here.
99
123
 
@@ -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,14 +8,14 @@ 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
@@ -23,4 +23,13 @@ module Lockie
23
23
  end
24
24
 
25
25
  Warden::Manager.after_set_user do |record, warden, options|
26
+ session_key = "warden.uls-#{record.class.name.underscore}-#{record.id}"
27
+ last_session_access = warden.request.session[session_key]
28
+
29
+ if last_session_access && Time.parse(last_session_access) < Time.now
30
+ # session expired
31
+ warden.logout
32
+ end
33
+
34
+ warden.request.session[session_key] = Time.now + Lockie.config.session_timeout
26
35
  end
@@ -1,3 +1,3 @@
1
1
  module Lockie
2
- VERSION = '0.2.11'
2
+ VERSION = '0.3.0'
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.11
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melvin Sembrano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-19 00:00:00.000000000 Z
11
+ date: 2020-07-24 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