@@ -48,7 +48,7 @@ import PostgREST.Auth.JwtCache (lookupJwtCache)
48
48
import PostgREST.Auth.Types (AuthResult (.. ))
49
49
import PostgREST.Config (AppConfig (.. ), FilterExp (.. ),
50
50
JSPath , JSPathExp (.. ))
51
- import PostgREST.Error (Error (.. ))
51
+ import PostgREST.Error (Error (.. ), JwtError ( .. ) )
52
52
53
53
import Protolude
54
54
@@ -57,20 +57,20 @@ import Protolude
57
57
parseToken :: AppConfig -> ByteString -> UTCTime -> ExceptT Error IO JSON. Value
58
58
parseToken _ " " _ = return JSON. emptyObject
59
59
parseToken AppConfig {.. } token time = do
60
- secret <- liftEither . maybeToRight JwtTokenMissing $ configJWKS
60
+ secret <- liftEither . maybeToRight ( JwtErr JwtTokenMissing ) $ configJWKS
61
61
eitherContent <- liftIO $ JWT. decode (JWT. keys secret) Nothing token
62
- content <- liftEither . mapLeft jwtDecodeError $ eitherContent
63
- liftEither $ verifyClaims content
62
+ content <- liftEither . mapLeft ( JwtErr . jwtDecodeError) $ eitherContent
63
+ liftEither $ mapLeft JwtErr $ verifyClaims content
64
64
where
65
65
-- TODO: Improve errors, those were just taken as-is from hs-jose to avoid
66
66
-- breaking changes.
67
- jwtDecodeError :: JWT. JwtError -> Error
67
+ jwtDecodeError :: JWT. JwtError -> JwtError
68
68
jwtDecodeError (JWT. KeyError _) = JwtTokenInvalid " JWSError JWSInvalidSignature"
69
69
jwtDecodeError JWT. BadCrypto = JwtTokenInvalid " JWSError (CompactDecodeError Invalid number of parts: Expected 3 parts; got 2)"
70
70
jwtDecodeError (JWT. BadAlgorithm _) = JwtTokenInvalid " JWSError JWSNoSignatures"
71
71
jwtDecodeError e = JwtTokenInvalid $ show e
72
72
73
- verifyClaims :: JWT. JwtContent -> Either Error JSON. Value
73
+ verifyClaims :: JWT. JwtContent -> Either JwtError JSON. Value
74
74
verifyClaims (JWT. Jws (_, claims)) = case JSON. decodeStrict claims of
75
75
Nothing -> Left $ JwtTokenInvalid " Parsing claims failed"
76
76
Just (JSON. Object mclaims)
@@ -110,7 +110,7 @@ parseClaims :: Monad m =>
110
110
AppConfig -> JSON. Value -> ExceptT Error m AuthResult
111
111
parseClaims AppConfig {.. } jclaims@ (JSON. Object mclaims) = do
112
112
-- role defaults to anon if not specified in jwt
113
- role <- liftEither . maybeToRight JwtTokenRequired $
113
+ role <- liftEither . maybeToRight ( JwtErr JwtTokenRequired ) $
114
114
unquoted <$> walkJSPath (Just jclaims) configJwtRoleClaimKey <|> configDbAnonRole
115
115
return AuthResult
116
116
{ authClaims = mclaims & KM. insert " role" (JSON. toJSON $ decodeUtf8 role)
0 commit comments