refactor: move parseSecret out of App.postgrest

parseSecret only needs to be computed once, after the config is read.
This commit is contained in:
steve-chavez
2020-07-13 11:30:16 -05:00
committed by Steve Chavez
parent 96a16a377f
commit 0ff05edd16
5 changed files with 43 additions and 30 deletions
+4 -4
View File
@@ -58,14 +58,14 @@ jwtClaims attempt =
-}
attemptJwtClaims :: Maybe JWKSet -> Maybe StringOrURI -> LByteString -> UTCTime -> Maybe JSPath -> IO JWTAttempt
attemptJwtClaims _ _ "" _ _ = return $ JWTClaims M.empty
attemptJwtClaims secret audience payload time jspath =
case secret of
attemptJwtClaims maybeSecret audience payload time jspath =
case maybeSecret of
Nothing -> return JWTMissingSecret
Just s -> do
Just secret -> do
let validation = set allowedSkew 1 $ defaultJWTValidationSettings (maybe (const True) (==) audience)
eJwt <- runExceptT $ do
jwt <- decodeCompact payload
verifyClaimsAt validation s time jwt
verifyClaimsAt validation secret time jwt
return $ case eJwt of
Left e -> JWTInvalid e
Right jwt -> JWTClaims $ claims2map jwt jspath