Skip to content

Commit 98405fd

Browse files
authored
allow x-hasura- req headers for jwt unauth role, closes hasura#1686 (hasura#1689)
1 parent d9882fc commit 98405fd

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

server/src-lib/Hasura/HTTP.hs

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Hasura.HTTP
22
( wreqOptions
33
, HttpException(..)
4+
, hdrsToText
45
) where
56

67
import Control.Lens hiding ((.=))
@@ -12,8 +13,16 @@ import qualified Network.HTTP.Client as HTTP
1213
import qualified Network.HTTP.Types as HTTP
1314
import qualified Network.Wreq as Wreq
1415

16+
import Data.CaseInsensitive (original)
17+
import Hasura.Server.Utils (bsToTxt)
1518
import Hasura.Server.Version (currentVersion)
1619

20+
hdrsToText :: [HTTP.Header] -> [(Text, Text)]
21+
hdrsToText hdrs =
22+
[ (bsToTxt $ original hdrName, bsToTxt hdrVal)
23+
| (hdrName, hdrVal) <- hdrs
24+
]
25+
1726
wreqOptions :: HTTP.Manager -> [HTTP.Header] -> Wreq.Options
1827
wreqOptions manager hdrs =
1928
Wreq.defaults

server/src-lib/Hasura/Server/Auth.hs

-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ module Hasura.Server.Auth
2222
import Control.Exception (try)
2323
import Control.Lens
2424
import Data.Aeson
25-
import Data.CaseInsensitive (CI (..), original)
2625
import Data.IORef (newIORef)
2726

2827
import qualified Data.Aeson as J
@@ -73,12 +72,6 @@ data AuthMode
7372
| AMAdminSecretAndJWT !AdminSecret !JWTCtx !(Maybe RoleName)
7473
deriving (Show, Eq)
7574

76-
hdrsToText :: [N.Header] -> [(T.Text, T.Text)]
77-
hdrsToText hdrs =
78-
[ (bsToTxt $ original hdrName, bsToTxt hdrVal)
79-
| (hdrName, hdrVal) <- hdrs
80-
]
81-
8275
mkAuthMode
8376
:: ( MonadIO m
8477
, MonadError T.Text m

server/src-lib/Hasura/Server/Auth/JWT.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ processJwt jwtCtx headers mUnAuthRole =
183183

184184
withoutAuthZHeader = do
185185
unAuthRole <- maybe missingAuthzHeader return mUnAuthRole
186-
return $ mkUserInfo unAuthRole $ mkUserVars []
186+
return $ mkUserInfo unAuthRole $ mkUserVars $ hdrsToText headers
187+
187188
missingAuthzHeader =
188189
throw400 InvalidHeaders "Missing Authorization header in JWT authentication mode"
189190

0 commit comments

Comments
 (0)