From 4e6a6c0ce626690a3c58f31b1f34bef521372eaa Mon Sep 17 00:00:00 2001 From: aaron levin Date: Thu, 7 Jan 2016 22:57:37 +0100 Subject: [PATCH] Use BasicAuth realm as its Config tag. For a given realm, there should only be one implementation, so the realm already serves as a unique identifier to configure BasicAuth from the Config perspective. This makes for less noise in the BasicAuth type. --- servant-server/src/Servant/Server/Internal.hs | 10 +++++----- servant/src/Servant/API/Auth.hs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/servant-server/src/Servant/Server/Internal.hs b/servant-server/src/Servant/Server/Internal.hs index 9dacd693..76cb2b76 100644 --- a/servant-server/src/Servant/Server/Internal.hs +++ b/servant-server/src/Servant/Server/Internal.hs @@ -467,16 +467,16 @@ instance HasServer api => HasServer (HttpVersion :> api) where route (Proxy :: Proxy api) cfg (passToServer subserver $ httpVersion req) instance (KnownSymbol realm, HasServer api) - => HasServer (BasicAuth tag realm usr :> api) where - type ServerT (BasicAuth tag realm usr :> api) m = usr -> ServerT api m - type HasCfg (BasicAuth tag realm usr :> api) c - = (HasConfigEntry c tag (BasicAuthCheck usr), HasCfg api c) + => HasServer (BasicAuth realm usr :> api) where + type ServerT (BasicAuth realm usr :> api) m = usr -> ServerT api m + type HasCfg (BasicAuth realm usr :> api) c + = (HasConfigEntry c realm (BasicAuthCheck usr), HasCfg api c) route Proxy cfg subserver = WithRequest $ \ request -> route (Proxy :: Proxy api) cfg (subserver `addAuthCheck` authCheck request) where realm = BC8.pack $ symbolVal (Proxy :: Proxy realm) - baCfg = getConfigEntry (Proxy :: Proxy tag) cfg + baCfg = getConfigEntry (Proxy :: Proxy realm) cfg authCheck req = runBasicAuth req realm baCfg diff --git a/servant/src/Servant/API/Auth.hs b/servant/src/Servant/API/Auth.hs index 61d52b05..db2ab653 100644 --- a/servant/src/Servant/API/Auth.hs +++ b/servant/src/Servant/API/Auth.hs @@ -16,5 +16,5 @@ import GHC.TypeLits (Symbol) -- In Basic Auth, username and password are base64-encoded and transmitted via -- the @Authorization@ header. Handshakes are not required, making it -- relatively efficient. -data BasicAuth config (realm :: Symbol) usr +data BasicAuth (realm :: Symbol) usr deriving (Typeable)