@@ -59,43 +59,43 @@ lookupJwtCache jwtCacheState token parseJwt utc = do
59
59
authResult <- parseJwt
60
60
61
61
case authResult of
62
- Right res -> do
62
+ Right result -> do
63
63
-- insert token -> update cache -> return token
64
- let jwtCache'' = C. insert token res jwtCache'
64
+ let jwtCache'' = C. insert token result jwtCache'
65
65
I. writeIORef jwtCacheIORef jwtCache''
66
- return $ Right res
66
+ return $ Right result
67
67
Left e -> do
68
68
-- update cache after lookup -> return error
69
69
I. writeIORef jwtCacheIORef jwtCache'
70
70
return $ Left e
71
71
72
- Just res -> -- CACHE HIT
72
+ Just result -> -- CACHE HIT
73
73
74
74
-- For cache hit, we get the result from cache, we check the
75
75
-- exp claim. If it expired, we delete it from cache and parse
76
76
-- the jwt. Otherwise, the hit result is valid, so we return it
77
77
78
- if isExpClaimExpired res utc then do
78
+ if isExpClaimExpired result utc then do
79
79
-- delete token -> update cache -> parse token
80
80
let (jwtCache'',_) = C. delete token jwtCache'
81
81
I. writeIORef jwtCacheIORef jwtCache''
82
82
parseJwt
83
83
else do
84
84
-- update cache afte lookup -> return result
85
85
I. writeIORef jwtCacheIORef jwtCache'
86
- return $ Right res
86
+ return $ Right result
87
87
88
88
89
89
type Expired = Bool
90
90
91
91
-- | Check if exp claim is expired when looked up from cache
92
92
isExpClaimExpired :: AuthResult -> UTCTime -> Expired
93
- isExpClaimExpired res utc =
93
+ isExpClaimExpired result utc =
94
94
case expireJSON of
95
95
Nothing -> False -- if exp not present then it is valid
96
96
Just (JSON. Number expiredAt) -> (sciToInt expiredAt - now) < 0
97
97
Just _ -> False -- if exp is not a number then valid
98
98
where
99
- expireJSON = KM. lookup " exp" (authClaims res )
99
+ expireJSON = KM. lookup " exp" (authClaims result )
100
100
now = (floor . nominalDiffTimeToSeconds . utcTimeToPOSIXSeconds) utc :: Int
101
101
sciToInt = fromMaybe 0 . Sci. toBoundedInteger
0 commit comments