parent
bf824a3889
commit
3e99698ae2
4 changed files with 34 additions and 7 deletions
|
@ -218,7 +218,10 @@ type GenAuthAPI =
|
||||||
genAuthAPI :: Proxy GenAuthAPI
|
genAuthAPI :: Proxy GenAuthAPI
|
||||||
genAuthAPI = Proxy
|
genAuthAPI = Proxy
|
||||||
|
|
||||||
type instance AuthServerData (AuthProtect "auth-tag") = ()
|
instance HasAuthServerData (AuthProtect "auth-tag") where
|
||||||
|
AuthServerData (AuthProtect "auth-tag") = ()
|
||||||
|
|
||||||
|
-- type instance AuthServerData (AuthProtect "auth-tag") = ()
|
||||||
type instance AuthClientData (AuthProtect "auth-tag") = ()
|
type instance AuthClientData (AuthProtect "auth-tag") = ()
|
||||||
|
|
||||||
genAuthHandler :: AuthHandler Request ()
|
genAuthHandler :: AuthHandler Request ()
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
{-# LANGUAGE UndecidableInstances #-}
|
{-# LANGUAGE UndecidableInstances #-}
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
|
||||||
module Servant.Server.Experimental.Auth where
|
module Servant.Server.Experimental.Auth where
|
||||||
|
|
||||||
|
@ -31,13 +32,21 @@ import Servant.Server.Internal.RoutingApplication (addAuthCheck,
|
||||||
withRequest)
|
withRequest)
|
||||||
import Servant.Server.Internal.ServantErr (Handler)
|
import Servant.Server.Internal.ServantErr (Handler)
|
||||||
|
|
||||||
|
import GHC.TypeLits
|
||||||
|
|
||||||
-- * General Auth
|
-- * General Auth
|
||||||
|
|
||||||
-- | Specify the type of data returned after we've authenticated a request.
|
-- | Specify the type of data returned after we've authenticated a request.
|
||||||
-- quite often this is some `User` datatype.
|
-- quite often this is some `User` datatype.
|
||||||
--
|
--
|
||||||
-- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
|
-- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE
|
||||||
type family AuthServerData a :: *
|
-- type family AuthServerData a :: *
|
||||||
|
class HasAuthServerData a where
|
||||||
|
|
||||||
|
type AuthServerData a :: *
|
||||||
|
|
||||||
|
instance {-# OVERLAPPING #-} HasAuthServerData a where
|
||||||
|
type AuthServerData a = TypeError ('Text "aha this should never occur")
|
||||||
|
|
||||||
-- | Handlers for AuthProtected resources
|
-- | Handlers for AuthProtected resources
|
||||||
--
|
--
|
||||||
|
|
|
@ -61,7 +61,7 @@ import Test.Hspec.Wai (get, liftIO, matchHeaders,
|
||||||
import Servant.Server.Internal.BasicAuth (BasicAuthCheck(BasicAuthCheck),
|
import Servant.Server.Internal.BasicAuth (BasicAuthCheck(BasicAuthCheck),
|
||||||
BasicAuthResult(Authorized,Unauthorized))
|
BasicAuthResult(Authorized,Unauthorized))
|
||||||
import Servant.Server.Experimental.Auth
|
import Servant.Server.Experimental.Auth
|
||||||
(AuthHandler, AuthServerData,
|
(AuthHandler, HasAuthServerData, AuthServerData,
|
||||||
mkAuthHandler)
|
mkAuthHandler)
|
||||||
import Servant.Server.Internal.Context
|
import Servant.Server.Internal.Context
|
||||||
(NamedContext(..))
|
(NamedContext(..))
|
||||||
|
@ -71,8 +71,20 @@ import Servant.Server.Internal.Context
|
||||||
-- This declaration simply checks that all instances are in place.
|
-- This declaration simply checks that all instances are in place.
|
||||||
_ = serveWithContext comprehensiveAPI comprehensiveApiContext
|
_ = serveWithContext comprehensiveAPI comprehensiveApiContext
|
||||||
|
|
||||||
comprehensiveApiContext :: Context '[NamedContext "foo" '[]]
|
authCheck :: BasicAuthCheck String
|
||||||
comprehensiveApiContext = NamedContext EmptyContext :. EmptyContext
|
authCheck = BasicAuthCheck check
|
||||||
|
where
|
||||||
|
check _ = return (Authorized "servant")
|
||||||
|
|
||||||
|
authHandler :: AuthHandler Request String
|
||||||
|
authHandler =
|
||||||
|
let handler req = return "foo"
|
||||||
|
in mkAuthHandler handler
|
||||||
|
|
||||||
|
-- type instance AuthServerData (AuthProtect "foo") = String
|
||||||
|
|
||||||
|
comprehensiveApiContext :: Context '[AuthHandler Request String, BasicAuthCheck String, NamedContext "foo" '[]]
|
||||||
|
comprehensiveApiContext = authHandler :. authCheck :. NamedContext EmptyContext :. EmptyContext
|
||||||
|
|
||||||
-- * Specs
|
-- * Specs
|
||||||
|
|
||||||
|
@ -637,7 +649,8 @@ genAuthServer :: Server GenAuthAPI
|
||||||
genAuthServer = const (return tweety)
|
genAuthServer = const (return tweety)
|
||||||
:<|> (\ _ respond -> respond $ responseLBS imATeaPot418 [] "")
|
:<|> (\ _ respond -> respond $ responseLBS imATeaPot418 [] "")
|
||||||
|
|
||||||
type instance AuthServerData (AuthProtect "auth") = ()
|
instance {-# OVERLAPS #-} HasAuthServerData (AuthProtect "auth") where
|
||||||
|
type AuthServerData (AuthProtect "auth") = ()
|
||||||
|
|
||||||
genAuthContext :: Context '[AuthHandler Request ()]
|
genAuthContext :: Context '[AuthHandler Request ()]
|
||||||
genAuthContext =
|
genAuthContext =
|
||||||
|
|
|
@ -36,8 +36,10 @@ type ComprehensiveAPIWithoutRaw =
|
||||||
Vault :> GET :<|>
|
Vault :> GET :<|>
|
||||||
Verb 'POST 204 '[JSON] NoContent :<|>
|
Verb 'POST 204 '[JSON] NoContent :<|>
|
||||||
Verb 'POST 204 '[JSON] Int :<|>
|
Verb 'POST 204 '[JSON] Int :<|>
|
||||||
|
BasicAuth "foo" String :> GET :<|>
|
||||||
WithNamedContext "foo" '[] GET :<|>
|
WithNamedContext "foo" '[] GET :<|>
|
||||||
CaptureAll "foo" Int :> GET
|
CaptureAll "foo" Int :> GET :<|>
|
||||||
|
AuthProtect "foo" :> GET
|
||||||
|
|
||||||
comprehensiveAPIWithoutRaw :: Proxy ComprehensiveAPIWithoutRaw
|
comprehensiveAPIWithoutRaw :: Proxy ComprehensiveAPIWithoutRaw
|
||||||
comprehensiveAPIWithoutRaw = Proxy
|
comprehensiveAPIWithoutRaw = Proxy
|
||||||
|
|
Loading…
Reference in a new issue