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.
This commit is contained in:
parent
f6bdfa3c05
commit
4e6a6c0ce6
2 changed files with 6 additions and 6 deletions
|
@ -467,16 +467,16 @@ instance HasServer api => HasServer (HttpVersion :> api) where
|
||||||
route (Proxy :: Proxy api) cfg (passToServer subserver $ httpVersion req)
|
route (Proxy :: Proxy api) cfg (passToServer subserver $ httpVersion req)
|
||||||
|
|
||||||
instance (KnownSymbol realm, HasServer api)
|
instance (KnownSymbol realm, HasServer api)
|
||||||
=> HasServer (BasicAuth tag realm usr :> api) where
|
=> HasServer (BasicAuth realm usr :> api) where
|
||||||
type ServerT (BasicAuth tag realm usr :> api) m = usr -> ServerT api m
|
type ServerT (BasicAuth realm usr :> api) m = usr -> ServerT api m
|
||||||
type HasCfg (BasicAuth tag realm usr :> api) c
|
type HasCfg (BasicAuth realm usr :> api) c
|
||||||
= (HasConfigEntry c tag (BasicAuthCheck usr), HasCfg api c)
|
= (HasConfigEntry c realm (BasicAuthCheck usr), HasCfg api c)
|
||||||
|
|
||||||
route Proxy cfg subserver = WithRequest $ \ request ->
|
route Proxy cfg subserver = WithRequest $ \ request ->
|
||||||
route (Proxy :: Proxy api) cfg (subserver `addAuthCheck` authCheck request)
|
route (Proxy :: Proxy api) cfg (subserver `addAuthCheck` authCheck request)
|
||||||
where
|
where
|
||||||
realm = BC8.pack $ symbolVal (Proxy :: Proxy realm)
|
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
|
authCheck req = runBasicAuth req realm baCfg
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,5 +16,5 @@ import GHC.TypeLits (Symbol)
|
||||||
-- In Basic Auth, username and password are base64-encoded and transmitted via
|
-- In Basic Auth, username and password are base64-encoded and transmitted via
|
||||||
-- the @Authorization@ header. Handshakes are not required, making it
|
-- the @Authorization@ header. Handshakes are not required, making it
|
||||||
-- relatively efficient.
|
-- relatively efficient.
|
||||||
data BasicAuth config (realm :: Symbol) usr
|
data BasicAuth (realm :: Symbol) usr
|
||||||
deriving (Typeable)
|
deriving (Typeable)
|
||||||
|
|
Loading…
Reference in a new issue