jwt_keeper 3.3.0 → 4.0.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: b2c902b7848d7fe72b7ad437badc5cf549b299d4b2ae2dc9150b7f42d63855a3
4
- data.tar.gz: 77a18a0cfeb2b198f13affa3792feaeb1235d5fa2f6ae599038bb3e2245b41b2
3
+ metadata.gz: 8e0b54e0b218b816c8bd261c723ec33c054d085ef521d0dbe145cbc51ae9805c
4
+ data.tar.gz: 30b605d2628612a0810897528ea73d8fbf907d15d59cb01f7172bd282382ac00
5
5
  SHA512:
6
- metadata.gz: bc177da58d088bdaeeba97049628d0908f05ef9bd717674a34b511a14e70289604a87647c01853ec3aeb988fb80cd95f4c4a96d0741a1133efc72f2138b9bd98
7
- data.tar.gz: 97dde3b11a5584357028abb7d9523d548c53ccb8e0211a4b31089f177747c1d9fca7521bf4984837a540ec2c46080a51adacd30e322fcd4408e6d8d732cad21e
6
+ metadata.gz: 8caacceede25c63e353a17ab39bed5b06581e2013c66ca9af22c29b312a61fc7fff079e270befadaaaf5a8488d64a1851344a9609b5b1335a81d15358cda2756
7
+ data.tar.gz: 22ade2f9b71c1cf0eed4f15967cde19731c533002445e3fefd2013838a1ef4628071c9ce72b8dd600d75d3f9f1b37160ea35dc225a96eebb396cdf10f3cc14d7
data/README.md CHANGED
@@ -32,11 +32,13 @@ raw_token_string = token.to_jwt
32
32
  The designed rails token flow is to receive and respond to requests with the token being present in the `Authorization` part of the header. This is to allow us to seamlessly rotate the tokens on the fly without having to rebuff the request as part of the user flow. Automatic rotation happens as part of the `require_authentication` action, meaning that you will always get the latest token data as created by `generate_claims` in your controllers. This new token is added to the response with the `write_authentication_token` action.
33
33
 
34
34
  ```bash
35
- rake generate jwt_keeper:install
35
+ rails generate jwt_keeper:install
36
36
  ```
37
37
 
38
38
  ```ruby
39
39
  class ApplicationController < ActionController::Base
40
+ include JWTKeeper::Controller
41
+
40
42
  before_action :require_authentication
41
43
 
42
44
  def not_authenticated
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  JWTKeeper.configure do |config|
2
4
  # The time to expire for the tokens
3
5
  # config.expiry = 1.hour
@@ -26,6 +28,9 @@ JWTKeeper.configure do |config|
26
28
 
27
29
  # the location of redis config file
28
30
  # config.redis_connection = Redis.new(connection_options)
31
+ # config.redis_connection = ConnectionPool.new(size: ENV.fetch('RAILS_MAX_THREADS', 5)) do
32
+ # Redis.new(url: ENV['REDISCLOUD_URL'] || 'redis://localhost:6379/')
33
+ # end
29
34
 
30
35
  # A unique idenfitier for the token version.
31
36
  # config.version = 1
@@ -23,6 +23,4 @@ module JWTKeeper
23
23
 
24
24
  @configuration = new_configuration.freeze
25
25
  end
26
-
27
- require 'jwt_keeper/engine' if defined?(Rails)
28
26
  end
@@ -29,7 +29,7 @@ module JWTKeeper
29
29
  @authentication_token ||=
30
30
  JWTKeeper::Token.find(
31
31
  request.headers['Authorization'].split.last,
32
- cookies.signed['jwt_keeper']
32
+ defined?(cookies) && cookies.signed['jwt_keeper']
33
33
  )
34
34
  end
35
35
 
@@ -39,7 +39,7 @@ module JWTKeeper
39
39
  def write_authentication_token(token)
40
40
  return clear_authentication_token if token.nil?
41
41
  response.headers['Authorization'] = "Bearer #{token.to_jwt}"
42
- cookies.signed['jwt_keeper'] = token.to_cookie
42
+ defined?(cookies) && cookies.signed['jwt_keeper'] = token.to_cookie
43
43
  @authentication_token = token
44
44
  end
45
45
 
@@ -47,7 +47,7 @@ module JWTKeeper
47
47
  # @return [void]
48
48
  def clear_authentication_token
49
49
  response.headers['Authorization'] = nil
50
- cookies.delete('jwt_keeper')
50
+ defined?(cookies) && cookies.delete('jwt_keeper')
51
51
  @authentication_token = nil
52
52
  end
53
53
 
@@ -27,12 +27,28 @@ module JWTKeeper
27
27
 
28
28
  # @!visibility private
29
29
  def set_with_expiry(jti, seconds, type)
30
- JWTKeeper.configuration.redis_connection.setex(jti, seconds, type)
30
+ redis = JWTKeeper.configuration.redis_connection
31
+
32
+ if redis.is_a?(Redis)
33
+ redis.setex(jti, seconds, type)
34
+ elsif defined?(ConnectionPool) && redis.is_a?(ConnectionPool)
35
+ redis.with { |conn| conn.setex(jti, seconds, type) }
36
+ else
37
+ throw 'Bad Redis Connection'
38
+ end
31
39
  end
32
40
 
33
41
  # @!visibility private
34
42
  def get(jti)
35
- JWTKeeper.configuration.redis_connection.get(jti)
43
+ redis = JWTKeeper.configuration.redis_connection
44
+
45
+ if redis.is_a?(Redis)
46
+ redis.get(jti)
47
+ elsif defined?(ConnectionPool) && redis.is_a?(ConnectionPool)
48
+ redis.with { |conn| conn.get(jti) }
49
+ else
50
+ throw 'Bad Redis Connection'
51
+ end
36
52
  end
37
53
  end
38
54
  end
@@ -1,4 +1,4 @@
1
1
  # Gem Version
2
2
  module JWTKeeper
3
- VERSION = '3.3.0'.freeze
3
+ VERSION = '4.0.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt_keeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rivera
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-11 00:00:00.000000000 Z
12
+ date: 2020-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler