fb-jwt-auth 0.2.2 → 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: a361b57c2b001ce5d99eae92c8c90536a478d0e27e5d93417dfa157dfc92fc54
4
- data.tar.gz: e9ec232adbdc8bc109a9f6e27e57fb5ac17a2289d69ba029dbde7b6f71f928b0
3
+ metadata.gz: 809db265860e3142598f429c53482e4b642543717c83cab5c6fbe46fd4834ee5
4
+ data.tar.gz: a26191f1f776d29b42f3095f4ae9c9dca20d032ab31f8add3efd7dbca99239a9
5
5
  SHA512:
6
- metadata.gz: d742d7ede999d0695a3d72da858c8c8314382b31539f4df7156c97c5ea01e45e0b4833952b05eeffd97fc172b6a675726829282e2ad594654d445dacf5220e9d
7
- data.tar.gz: 45366b1a2238884d9b1cd5818dde5ef5f63340461d15867eb86b7e6852f132876baf3174c14397e25cc0d7d4b0093fa9867628b05a85015d95693ad583b69b86
6
+ metadata.gz: 9c86735004359b8c7b0261808d0bf90ed5b7ebd56cca83f83dcbb950c1894825df06051c8fc85f23ceef3c6cc79c16a05fd1cd293676d80832dd3e2c3843e1f6
7
+ data.tar.gz: 318864900ac94c5f51c1e781ba5aa9b990604acb85084db810144963cb93941465b7428931dafd71d0918343d4cb925778b16b3a5c8bc48899373923332d6317
@@ -44,8 +44,7 @@ module Fb
44
44
  application_details = find_application_info
45
45
 
46
46
  begin
47
- hmac_secret = public_key(application_details)
48
- payload, _header = decode(hmac_secret: hmac_secret)
47
+ payload, _header = retrieve_and_decode_public_key(application_details)
49
48
  rescue StandardError => e
50
49
  error_message = "Token is not valid: error #{e}"
51
50
  logger.debug(error_message)
@@ -67,6 +66,15 @@ module Fb
67
66
  payload
68
67
  end
69
68
 
69
+ def retrieve_and_decode_public_key(application_details)
70
+ hmac_secret = public_key(application_details)
71
+ decode(hmac_secret: hmac_secret)
72
+ rescue JWT::VerificationError
73
+ logger.debug('First validation failed. Requesting non cached public key')
74
+ hmac_secret = public_key(application_details.merge(ignore_cache: true))
75
+ decode(hmac_secret: hmac_secret)
76
+ end
77
+
70
78
  def decode(verify: true, hmac_secret: nil)
71
79
  JWT.decode(
72
80
  token,
@@ -12,9 +12,10 @@ class Fb::Jwt::Auth::ServiceTokenClient
12
12
 
13
13
  attr_accessor :application, :namespace, :root_url, :api_version
14
14
 
15
- def initialize(application:, namespace: nil)
15
+ def initialize(application:, namespace: nil, ignore_cache: false)
16
16
  @application = application
17
17
  @namespace = namespace
18
+ @ignore_cache = ignore_cache
18
19
  @root_url = Fb::Jwt::Auth.service_token_cache_root_url
19
20
  @api_version = Fb::Jwt::Auth.service_token_cache_api_version || :v2
20
21
  end
@@ -38,8 +39,14 @@ class Fb::Jwt::Auth::ServiceTokenClient
38
39
 
39
40
  private
40
41
 
42
+ attr_reader :ignore_cache
43
+
41
44
  def public_key_uri
42
- URI.join(root_url, version_url)
45
+ URI.join(root_url, "#{version_url}#{query_param}")
46
+ end
47
+
48
+ def query_param
49
+ ignore_cache ? '?ignore_cache=true' : ''
43
50
  end
44
51
 
45
52
  def version_url
@@ -1,7 +1,7 @@
1
1
  module Fb
2
2
  module Jwt
3
3
  class Auth
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb-jwt-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Form builder developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2020-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt