Skip to content

Commit 012b811

Browse files
committed
refactor: Rename Auth.getAuthResult to Auth.authenticate
getAuthResult suggests authentication result is already available and it just needs to be read. But in reality this function performs full JWT validation (ie. parsing, signature verification, claims validation). Renaming it to authenticate so that the name is no longer misleading.
1 parent 3ed10e8 commit 012b811

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/PostgREST/App.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ postgrestResponse appState maybeSchemaCache req = do
196196
let observer = liftIO . AppState.getObserver appState
197197

198198
authResult@AuthResult{..} <-
199-
withTiming @"jwt" $ Auth.getAuthResult conf (liftIO $ AppState.getTime appState) (AppState.getJwtCacheState appState) $ ApiRequest.userBearerAuth req
199+
withTiming @"jwt" $ Auth.authenticate conf (liftIO $ AppState.getTime appState) (AppState.getJwtCacheState appState) $ ApiRequest.userBearerAuth req
200200
-- save authRole
201201
tell $ pure authRole
202202

src/PostgREST/Auth.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ very simple authentication system inside the PostgreSQL database.
1515
{-# LANGUAGE LambdaCase #-}
1616
{-# LANGUAGE NamedFieldPuns #-}
1717
module PostgREST.Auth
18-
( getAuthResult )
18+
( authenticate )
1919
where
2020

2121
import Control.Monad.Error.Class
@@ -39,8 +39,8 @@ import Protolude
3939

4040
-- | Perform authentication and authorization
4141
-- Parse JWT and return AuthResult
42-
getAuthResult :: (MonadError Error m, MonadIO m) => AppConfig -> m UTCTime -> JwtCacheState -> Maybe ByteString -> m AuthResult
43-
getAuthResult cfg@AppConfig{configJwtRoleClaimKey, configDbAnonRole} getTime jwtCacheState token = do
42+
authenticate :: (MonadError Error m, MonadIO m) => AppConfig -> m UTCTime -> JwtCacheState -> Maybe ByteString -> m AuthResult
43+
authenticate cfg@AppConfig{configJwtRoleClaimKey, configDbAnonRole} getTime jwtCacheState token = do
4444
time <- getTime
4545
let
4646
parseClaims mclaims = do
@@ -60,7 +60,7 @@ getAuthResult cfg@AppConfig{configJwtRoleClaimKey, configDbAnonRole} getTime jwt
6060
unquoted v = LBS.toStrict $ JSON.encode v
6161

6262
parseClaims =<< lookupJwtCache jwtCacheState token
63-
{-# INLINABLE getAuthResult #-}
63+
{-# INLINABLE authenticate #-}
6464

6565
data ValidAud = VAString Text | VAArray [Text] deriving Generic
6666
instance JSON.FromJSON ValidAud where

0 commit comments

Comments
 (0)