jwt_sessions 2.1.0 → 2.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7981af52568346a34f4c308e76b19b88ddc264ea
4
- data.tar.gz: 48fe0cb349266922f0124a918c14e4c79c10d28b
3
+ metadata.gz: d92af5c82b767203a340f54627281a85eb5576ed
4
+ data.tar.gz: dce1a37bba83687b2815e757475d00e3f0a21fef
5
5
  SHA512:
6
- metadata.gz: 8c275a6504519c3447c36b9557223ba5403d87d590ba9d4d7215fc4f6580021a00a296b6daa71ef2e7f15c1fa61dd7fe0d1f9b62813ae63e93381e342a3e2640
7
- data.tar.gz: cafceae22f54838b7745f4e26deaf5eba969212f235552e1d2fde547608f6219e76a4482135a02e5b4cc94818dc5d1ec5c256c79b67907b6531e06df980dc6ff
6
+ metadata.gz: cc9b3e0a4bea5bab7560c38d8cb24b15b94f289c82acc9581206af29eed9890f0aa4987c126a59540ed6b1f02d126159714212e4fb08f6d470232d8f08b3eeb8
7
+ data.tar.gz: f689a7cc6c5de3bf0d8ffec6bc3d20d0abc86b1a71ab85b33a782c5a1fad491baaaedf449032e62547bd2b8fdc7a833d7f5ecb569d476077abec70dc3a3c354b
data/README.md CHANGED
@@ -294,6 +294,14 @@ JWTSessions.redis_db_name = '0'
294
294
  JWTSessions.token_prefix = 'jwt_' # used for redis db keys
295
295
  ```
296
296
 
297
+ You can also provide a Redis URL instead:
298
+
299
+ ```ruby
300
+ JWTSessions.redis_url = 'redis://localhost:6397'
301
+ ```
302
+
303
+ **NOTE:** if `REDIS_URL` environment variable is set it is used automatically.
304
+
297
305
  ##### JWT signature
298
306
 
299
307
  ```ruby
@@ -479,7 +487,14 @@ and selectively flush sessions by namespace
479
487
 
480
488
  ```ruby
481
489
  session = JWTSessions::Session.new(namespace: 'ie-sessions')
482
- session.flush_namespaced # will flush all sessions that belong to the same namespace
490
+ session.flush_namespaced # will flush all sessions which belong to the same namespace
491
+ ```
492
+
493
+ it's posible to flush access tokens only
494
+
495
+ ```ruby
496
+ session = JWTSessions::Session.new(namespace: 'ie-sessions')
497
+ session.flush_namespaced_access_tokens # will flush all access tokens which belong to the same namespace, but will keep refresh tokens
483
498
  ```
484
499
 
485
500
  To force flush of all app sessions
@@ -502,8 +517,15 @@ To logout with an access token `refresh_by_access_allowed` setting should be set
502
517
 
503
518
  ## Contributing
504
519
 
505
- Fork & Pull Request \
506
- RbNaCl and sodium cryptographic library are required for tests
520
+ Fork & Pull Request. \
521
+ RbNaCl and sodium cryptographic library are required for tests.
522
+
523
+ For MacOS see [these instructions](http://macappstore.org/libsodium/). \
524
+ For example, with Homebrew:
525
+
526
+ ```
527
+ brew install libsodium
528
+ ```
507
529
 
508
530
  ## License
509
531
 
@@ -2,8 +2,14 @@ module JWTSessions
2
2
  module RailsAuthorization
3
3
  include Authorization
4
4
 
5
- def request_headers
6
- ActionDispatch::Http::Headers.from_hash(request.headers)
5
+ if Rails::VERSION::MAJOR < 5
6
+ def request_headers
7
+ request.headers
8
+ end
9
+ else
10
+ def request_headers
11
+ ActionDispatch::Http::Headers.from_hash(request.headers)
12
+ end
7
13
  end
8
14
 
9
15
  def request_cookies
@@ -5,8 +5,8 @@ require 'redis'
5
5
  module JWTSessions
6
6
  class RedisTokenStore
7
7
  class << self
8
- def instance(redis_host, redis_port, redis_db_name, prefix)
9
- @_tokens_store ||= Redis.new(url: "redis://#{redis_host}:#{redis_port}/#{redis_db_name}")
8
+ def instance(redis_url, prefix)
9
+ @_tokens_store ||= Redis.new(url: redis_url)
10
10
  @_token_prefix ||= prefix
11
11
 
12
12
  new(@_tokens_store, @_token_prefix)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JWTSessions
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  end
data/lib/jwt_sessions.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'securerandom'
4
+ require 'uri'
4
5
 
5
6
  require 'jwt_sessions/errors'
6
7
  require 'jwt_sessions/token'
@@ -10,7 +11,7 @@ require 'jwt_sessions/csrf_token'
10
11
  require 'jwt_sessions/access_token'
11
12
  require 'jwt_sessions/session'
12
13
  require 'jwt_sessions/authorization'
13
- require 'jwt_sessions/rails_authorization'
14
+ require 'jwt_sessions/rails_authorization' if defined?(::Rails)
14
15
  require 'jwt_sessions/version'
15
16
 
16
17
  module JWTSessions
@@ -64,6 +65,17 @@ module JWTSessions
64
65
  end
65
66
  end
66
67
 
68
+ def redis_url
69
+ @redis_url ||= begin
70
+ redis_base_url = ENV['REDIS_URL'] || "redis://#{redis_host}:#{redis_port}"
71
+ URI.join(redis_base_url, redis_db_name).to_s
72
+ end
73
+ end
74
+
75
+ def redis_url=(url)
76
+ @redis_url = URI.join(url, redis_db_name).to_s
77
+ end
78
+
67
79
  def jwt_options
68
80
  @jwt_options ||= JWTOptions.new(*JWT::DefaultOptions::DEFAULT_OPTIONS.values)
69
81
  end
@@ -78,7 +90,7 @@ module JWTSessions
78
90
  end
79
91
 
80
92
  def token_store
81
- RedisTokenStore.instance(redis_host, redis_port, redis_db_name, token_prefix)
93
+ RedisTokenStore.instance(redis_url, token_prefix)
82
94
  end
83
95
 
84
96
  def validate?
@@ -35,4 +35,17 @@ class TestJWTSessions < Minitest::Test
35
35
  assert_equal JWTSessions.access_cookie, JWTSessions.cookie_by('access')
36
36
  assert_equal JWTSessions.refresh_cookie, JWTSessions.cookie_by('refresh')
37
37
  end
38
+
39
+ def test_redis_url
40
+ assert_equal 'redis://127.0.0.1:6379/0', JWTSessions.redis_url
41
+ end
42
+
43
+ def test_redis_url_with_env_var
44
+ JWTSessions.instance_variable_set(:@redis_url, nil)
45
+ ENV['REDIS_URL'] = 'rediska://locallol:2018/'
46
+ assert_equal 'rediska://locallol:2018/0', JWTSessions.redis_url
47
+ ENV.delete('REDIS_URL')
48
+ JWTSessions.instance_variable_set(:@redis_url, nil)
49
+ assert_equal 'redis://127.0.0.1:6379/0', JWTSessions.redis_url
50
+ end
38
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt_sessions
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yulia Oletskaya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-25 00:00:00.000000000 Z
11
+ date: 2018-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt