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 +4 -4
- data/lib/stytch/errors.rb +13 -0
- data/lib/stytch/m2m.rb +6 -9
- data/lib/stytch/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d5d25d2cefdc1dfb620d3c190fb883d8b33e33e3fba584825524968d416b8dc
|
4
|
+
data.tar.gz: 2168f866d3ce1a8f6bfe7a39618d857c5e835a33977f6147182055254a9b3ee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
114
|
-
|
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
|
-
|
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
|
-
|
133
|
-
return nil
|
130
|
+
raise TokenMissingScopeError.new(scope)
|
134
131
|
end
|
135
132
|
end
|
136
133
|
end
|
data/lib/stytch/version.rb
CHANGED