stytch 6.2.0 → 6.2.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: f191b11ecf499de4ea27a1eff18ada545ecfa999e46e18c9170d010161c0a08c
4
- data.tar.gz: 142be9df24b3b26f388407db08647f618d9910db51e25ca88fe11e35cfd28a18
3
+ metadata.gz: 9d5d25d2cefdc1dfb620d3c190fb883d8b33e33e3fba584825524968d416b8dc
4
+ data.tar.gz: 2168f866d3ce1a8f6bfe7a39618d857c5e835a33977f6147182055254a9b3ee3
5
5
  SHA512:
6
- metadata.gz: a85ad3a934eb36560641c7b37017bf0d3ff981a2df27d18440d8a714a52c9e1b5c6f16f2b4a8f9f261e51c5f1afd7e53175f8f39de18a6ae2bc354faa56e14a8
7
- data.tar.gz: aca18f76d5c72ae175ef53d92a2ad833cf078934e8ebf49fc3eac96cfb00e66db4295a7569809a294beef8220ba4e895f64edc17577213c283d2029c52036e32
6
+ metadata.gz: abbd1bb992381e8eec80668e88e5b048a546bee91da7e78f04d9e4029b9ab2515da6d87b14cdfbcd6f344d3670c4255c63d2079060a55a8013326227d1e2477e
7
+ data.tar.gz: 8e659c85efa1eaa046e81b37e738724d566db31ba32456ca8b36597daae4ed9e638df7dba4a0252bd4ba486f24ead89a5d4bbab2f83d7217376fc16828f96cff
data/lib/stytch/errors.rb CHANGED
@@ -22,4 +22,17 @@ module Stytch
22
22
  super
23
23
  end
24
24
  end
25
+
26
+ class JWTExpiredError < StandardError
27
+ def initialize(msg = 'JWT has expired')
28
+ super
29
+ end
30
+ end
31
+
32
+ class TokenMissingScopeError < StandardError
33
+ def initialize(scope)
34
+ msg = "Missing required scope #{scope}"
35
+ super(msg)
36
+ end
37
+ end
25
38
  end
data/lib/stytch/m2m.rb CHANGED
@@ -110,18 +110,16 @@ module Stytch
110
110
  # A map of custom claims present in the token.
111
111
  # The type of this field is +object+.
112
112
  def authenticate_token(access_token:, required_scopes: nil, max_token_age: nil)
113
- begin
114
- decoded_jwt = authenticate_token_local(access_token)
115
- rescue StandardError
116
- # Could not authenticate locally
117
- return nil
118
- end
113
+ # Intentionally allow this to re-raise if authentication fails
114
+ decoded_jwt = authenticate_token_local(access_token)
119
115
 
120
116
  iat_time = Time.at(decoded_jwt['iat']).to_datetime
121
117
 
122
118
  # Token too old
123
119
  unless max_token_age.nil?
124
- return nil if iat_time + max_token_age < Time.now
120
+ if iat_time + max_token_age < Time.now
121
+ raise JWTExpiredError
122
+ end
125
123
  end
126
124
 
127
125
  resp = marshal_jwt_into_response(decoded_jwt)
@@ -129,8 +127,7 @@ module Stytch
129
127
  unless required_scopes.nil?
130
128
  for scope in required_scopes
131
129
  unless resp['scopes'].include?(scope)
132
- # Token missing a required scope
133
- return nil
130
+ raise TokenMissingScopeError.new(scope)
134
131
  end
135
132
  end
136
133
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stytch
4
- VERSION = '6.2.0'
4
+ VERSION = '6.2.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stytch
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.0
4
+ version: 6.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - stytch