2929import Control.Applicative
3030import Control.Monad.Random
3131import Control.Monad.Trans.Maybe (MaybeT (.. ))
32+ import Crypto.JWT qualified as JWT
3233import Data.Aeson
3334import Data.Aeson qualified as Aeson
3435import Data.Binary
@@ -46,6 +47,7 @@ import Network.HTTP.Types qualified as Network
4647import Network.URI
4748import Network.Wai qualified as Wai
4849import Servant
50+ import Servant.Client.Core.Auth qualified as ServantAuth
4951import Servant.Server.Experimental.Auth qualified as ServantAuth
5052import Share.JWT
5153import Share.OAuth.Types
@@ -63,6 +65,8 @@ type AuthenticatedSession = Servant.AuthProtect "require-session"
6365
6466type instance ServantAuth. AuthServerData (Servant. AuthProtect " require-session" ) = Session
6567
68+ type instance ServantAuth. AuthClientData (Servant. AuthProtect " require-session" ) = JWT. SignedJWT
69+
6670-- | Requires a valid session cookie to be present in the request,
6771-- provides the authenticated user's user-id as an argument to the handler
6872--
@@ -71,6 +75,8 @@ type AuthenticatedUserId = Servant.AuthProtect "require-user-id"
7175
7276type instance ServantAuth. AuthServerData (AuthProtect " require-user-id" ) = UserId
7377
78+ type instance ServantAuth. AuthClientData (AuthProtect " require-user-id" ) = JWT. SignedJWT
79+
7480-- | Used for endpoints with optional auth.
7581-- Provides 'Just' the session if a valid session cookie is present in the request,
7682-- otherwise provides 'Nothing'.
@@ -80,13 +86,17 @@ type MaybeAuthenticatedSession = Servant.AuthProtect "maybe-session"
8086
8187type instance ServantAuth. AuthServerData (AuthProtect " maybe-session" ) = Maybe Session
8288
89+ type instance ServantAuth. AuthClientData (AuthProtect " maybe-session" ) = Maybe JWT. SignedJWT
90+
8391-- | Used for endpoints with optional auth.
8492-- Provides 'Just' the user ID if a valid session cookie is present in the request,
8593-- otherwise provides 'Nothing'.
8694type MaybeAuthenticatedUserId = Servant. AuthProtect " maybe-user-id"
8795
8896type instance ServantAuth. AuthServerData (AuthProtect " maybe-user-id" ) = Maybe UserId
8997
98+ type instance ServantAuth. AuthClientData (AuthProtect " maybe-user-id" ) = Maybe JWT. SignedJWT
99+
90100-- | An additional check to perform on a session. Returns True if valid, False otherwise.
91101type SessionCheck = (Session -> Handler Bool )
92102
0 commit comments