ripple_token 0.2.1 → 0.5.1

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
  SHA256:
3
- metadata.gz: 80df9846c357f7f07f1d79aa2f4d1e4f4521e5adde474ef6798f67204a05c443
4
- data.tar.gz: e0f9a30cf3dfe32a2c40909340fde9a27a3253450a969342960fe60fd609a145
3
+ metadata.gz: 9340efe777dcdb596e731768b6ca0d0781db3d74e162a1bc138b8d1d555c26ed
4
+ data.tar.gz: 33f413b201c9fc280d4a773f819374121b57b6591f7d347619e263f46278d785
5
5
  SHA512:
6
- metadata.gz: 0bbf3b3f2c4aea7aa04275cd197e440d1a2b95b6d6d0a89750ecae01789aac7e7d7ef4b0554a5476e9515e8ad629b3be511fb95efb97ffc58d8d21195136d759
7
- data.tar.gz: 13c81c3248f66c23b3cc29a20d11e8cd4f129e4f6ab65a3b97bcf7bea4533c82ccc288e4d85fd2437117481535635ed6c809c7c7442f74db09ee1c9f7b44e73e
6
+ metadata.gz: 01f1df20b2e3830a7462f1e416548abd4c6890be3755e1399092676917ea133d8cc832685214d980c01f1f2be0daaee1874d57414aa3c7ccbf895f99bfd4a54e
7
+ data.tar.gz: 7e612334e9b018e567f085586f1290a2c316d0636b3e7a55f7c4e6759d39892a5bb11dc3135996eeb20ddacda6c26a5e9983fe4167911d9942bfc8e10487f402
@@ -11,7 +11,7 @@ module RippleToken
11
11
  include HTTParty
12
12
 
13
13
  class << self
14
- delegate :public_paths, to: :configuration
14
+ delegate :public_paths, :logger, to: :configuration
15
15
 
16
16
  def configure
17
17
  @configuration = Configuration.new
@@ -5,6 +5,7 @@ module RippleToken
5
5
  attr_accessor :base_url,
6
6
  :realm,
7
7
  :public_key_ttl,
8
- :public_paths
8
+ :public_paths,
9
+ :logger
9
10
  end
10
11
  end
@@ -15,19 +15,25 @@ module RippleToken
15
15
  path = env['PATH_INFO']
16
16
 
17
17
  encoded_token = env['HTTP_AUTHORIZATION']&.gsub(/^Bearer /, '') || ''
18
- unless token.public_path? method, path
19
- raise MissingTokenError if encoded_token.nil? || encoded_token&.empty?
20
- end
21
- decoded_token = token.decode(encoded_token)
22
18
 
23
- store_user_details(decoded_token, env)
19
+ Client.logger.debug("Received #{encoded_token} token")
20
+
21
+ if encoded_token.nil? || encoded_token&.empty?
22
+ Client.logger.info('No token provided in request')
23
+ raise MissingTokenError unless token.public_path? method, path
24
+ else
25
+ store_user_details(encoded_token, env)
26
+ end
24
27
 
25
28
  @app.call(env)
26
29
  end
27
30
 
28
31
  private
29
32
 
30
- def store_user_details(decoded_token, env)
33
+ def store_user_details(encoded_token, env)
34
+ env['keycloak.raw_token'] = encoded_token
35
+ decoded_token = token.decode(encoded_token)
36
+
31
37
  env['keycloak.token'] = decoded_token
32
38
  env['keycloak.user_id'] = decoded_token['sub']
33
39
  env['keycloak.user_roles'] = decoded_token['realm_access']['roles']
@@ -7,22 +7,20 @@ module RippleToken
7
7
  end
8
8
 
9
9
  def decode(token)
10
- begin
11
- decoded_token = JWT.decode(token, public_key, true, { algorithm: 'RS256' })[0]
12
- raise ExpiredTokenError if expired? decoded_token
13
-
14
- decoded_token
15
- rescue JWT::DecodeError => e
16
- raise TokenDecodeError, e.message
17
- rescue JWT::ExpiredSignature => e
18
- raise ExpiredTokenError, e.message
19
- end
10
+ decoded_token = JWT.decode(token, public_key, true, { algorithm: 'RS256' })[0]
11
+ raise ExpiredTokenError if expired? decoded_token
12
+
13
+ decoded_token
14
+ rescue JWT::DecodeError => e
15
+ raise TokenDecodeError, e.message
16
+ rescue JWT::ExpiredSignature => e
17
+ raise ExpiredTokenError, e.message
20
18
  end
21
19
 
22
20
  def public_path?(method, path)
23
21
  return false if Client.public_paths.nil? || Client.public_paths.empty?
24
22
 
25
- return true if Client.public_paths[method]&.include? path
23
+ return true if Client.public_paths[method]&.select { |p| path[p] }&.any?
26
24
 
27
25
  false
28
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RippleToken
4
- VERSION = '0.2.1'
4
+ VERSION = '0.5.1'
5
5
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.add_dependency('activesupport', '6.0.3.1')
28
+ spec.add_dependency('activesupport', '~>6.0')
29
29
  spec.add_dependency('httparty', '0.18.1')
30
30
  spec.add_dependency('jwt', '2.2.1')
31
31
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripple_token
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hex Event Solutions Limited
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-22 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.3.1
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 6.0.3.1
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement