refactor: move role insertion in claims to PreQuery.hs
Also add a comment on `AuthResult` type to explain that we can also access the claims in the db using GUCs. Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
committed by
Steve Chavez
parent
1f54e2accc
commit
40a1fea916
@@ -16,7 +16,6 @@ module PostgREST.Auth.Jwt
|
||||
, parseClaims) where
|
||||
|
||||
import qualified Data.Aeson as JSON
|
||||
import qualified Data.Aeson.KeyMap as KM
|
||||
import qualified Data.ByteString as BS
|
||||
import qualified Data.ByteString.Internal as BS
|
||||
import qualified Data.ByteString.Lazy.Char8 as LBS
|
||||
@@ -118,7 +117,7 @@ parseClaims cfg@AppConfig{configJwtRoleClaimKey, configDbAnonRole} time mclaims
|
||||
role <- liftEither . maybeToRight (JwtErr JwtTokenRequired) $
|
||||
unquoted <$> walkJSPath (Just $ JSON.Object mclaims) configJwtRoleClaimKey <|> configDbAnonRole
|
||||
pure AuthResult
|
||||
{ authClaims = mclaims & KM.insert "role" (JSON.toJSON $ decodeUtf8 role)
|
||||
{ authClaims = mclaims
|
||||
, authRole = role
|
||||
}
|
||||
where
|
||||
|
||||
@@ -6,7 +6,9 @@ import qualified Data.Aeson as JSON
|
||||
import qualified Data.Aeson.KeyMap as KM
|
||||
import qualified Data.ByteString as BS
|
||||
|
||||
-- | Parse result for JWT Claims
|
||||
-- |
|
||||
-- Parse and store result for JWT Claims. Can be accessed in
|
||||
-- db through GUCs (for RLS etc)
|
||||
data AuthResult = AuthResult
|
||||
{ authClaims :: KM.KeyMap JSON.Value
|
||||
, authRole :: BS.ByteString
|
||||
|
||||
Reference in New Issue
Block a user