graphql-engine/server/src-lib/Hasura/Server/Config.hs
Karthikeyan Chinnakonda a26bc80496
accept a new argument claims_namespace_path in JWT config (#4365)
* add new optional field `claims_namespace_path` in JWT config

* return value when empty array is found in executeJSONPath

* update the docs related to claims_namespace_path

* improve encodeJSONPath, add property tests for parseJSONPath

* throw error if both claims_namespace_path and claims_namespace are set

* refactor the Data.Parser.JsonPath to Data.Parser.JSONPathSpec

* update the JWT docs

Co-Authored-By: Marion Schleifer <marion@hasura.io>

Co-authored-by: Marion Schleifer <marion@hasura.io>
Co-authored-by: rakeshkky <12475069+rakeshkky@users.noreply.github.com>
Co-authored-by: Tirumarai Selvan <tirumarai.selvan@gmail.com>
2020-04-16 12:15:21 +05:30

69 lines
1.8 KiB
Haskell

module Hasura.Server.Config
( runGetConfig
)
where
import Data.Aeson.Casing
import Data.Aeson.TH
import Hasura.Prelude
import Hasura.Server.Auth
import Hasura.Server.Auth.JWT
import Hasura.Server.Version (HasVersion, Version, currentVersion)
import qualified Hasura.GraphQL.Execute.LiveQuery.Options as LQ
data JWTInfo
= JWTInfo
{ jwtiClaimsNamespace :: !JWTConfigClaims
, jwtiClaimsFormat :: !JWTClaimsFormat
} deriving (Show, Eq)
$(deriveToJSON (aesonDrop 4 snakeCase) ''JWTInfo)
data ServerConfig
= ServerConfig
{ scfgVersion :: !Version
, scfgIsAdminSecretSet :: !Bool
, scfgIsAuthHookSet :: !Bool
, scfgIsJwtSet :: !Bool
, scfgJwt :: !(Maybe JWTInfo)
, scfgIsAllowListEnabled :: !Bool
, scfgLiveQueries :: !LQ.LiveQueriesOptions
} deriving (Show, Eq)
$(deriveToJSON (aesonDrop 4 snakeCase) ''ServerConfig)
runGetConfig :: HasVersion => AuthMode -> Bool -> LQ.LiveQueriesOptions -> ServerConfig
runGetConfig am isAllowListEnabled liveQueryOpts = ServerConfig
currentVersion
(isAdminSecretSet am)
(isAuthHookSet am)
(isJWTSet am)
(getJWTInfo am)
isAllowListEnabled
liveQueryOpts
isAdminSecretSet :: AuthMode -> Bool
isAdminSecretSet = \case
AMNoAuth -> False
_ -> True
isAuthHookSet :: AuthMode -> Bool
isAuthHookSet = \case
AMAdminSecretAndHook _ _ -> True
_ -> False
isJWTSet :: AuthMode -> Bool
isJWTSet = \case
AMAdminSecretAndJWT{} -> True
_ -> False
getJWTInfo :: AuthMode -> Maybe JWTInfo
getJWTInfo (AMAdminSecretAndJWT _ jwtCtx _) =
Just $ JWTInfo claimsNs format
where
claimsNs = jcxClaimNs jwtCtx
format = jcxClaimsFormat jwtCtx
getJWTInfo _ = Nothing