Skip to content

Commit 3679c5a

Browse files
authored
Merge pull request #1462 from spencerjanssen/auth-refactor
Remove unused UserInfo from Auth functions
2 parents 812ab5d + a049826 commit 3679c5a

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/Distribution/Server/Features/Html.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ mkHtmlCore ServerEnv{serverBaseURI, serverBlobStore}
650650
pkgVotes <- pkgNumVotes pkgname
651651
pkgScore <- pkgNumScore pkgname
652652
auth <- checkAuthenticated
653-
userRating <- case auth of Just (uid,_) -> pkgUserVote pkgname uid; _ -> return Nothing
653+
userRating <- case auth of Just uid -> pkgUserVote pkgname uid; _ -> return Nothing
654654
mdoctarblob <- queryDocumentation realpkg
655655
tags <- queryTagsForPackage pkgname
656656
rdeps <- queryReverseDeps pkgname

src/Distribution/Server/Features/Users.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ data UserFeature = UserFeature {
6868
-- | Require being logged in, giving the id of the current user.
6969
guardAuthenticated :: ServerPartE UserId,
7070
-- | Gets the authentication if it exists.
71-
checkAuthenticated :: ServerPartE (Maybe (UserId, UserInfo)),
71+
checkAuthenticated :: ServerPartE (Maybe UserId),
7272
-- | A hook to override the default authentication error in particular
7373
-- circumstances.
7474
authFailHook :: Hook Auth.AuthError (Maybe ErrorResponse),
@@ -487,7 +487,7 @@ userFeature templates usersState adminsState
487487
-- See note about "authn" cookie above
488488
guardAuthenticatedWithErrHook :: Users.Users -> ServerPartE UserId
489489
guardAuthenticatedWithErrHook users = do
490-
(uid,_) <- Auth.checkAuthenticated realm users userFeatureServerEnv
490+
uid <- Auth.checkAuthenticated realm users userFeatureServerEnv
491491
>>= either handleAuthError return
492492
addCookie Session (mkCookie "authn" "1")
493493
-- Set-Cookie:authn="1";Path=/;Version="1"
@@ -510,7 +510,7 @@ userFeature templates usersState adminsState
510510

511511
-- Check if there is an authenticated userid, and return info, if so.
512512
-- See note about "authn" cookie above
513-
checkAuthenticated :: ServerPartE (Maybe (UserId, UserInfo))
513+
checkAuthenticated :: ServerPartE (Maybe UserId)
514514
checkAuthenticated = do
515515
authn <- optional (lookCookieValue "authn")
516516
case authn of

src/Distribution/Server/Framework/Auth.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ guardAuthorised :: RealmName -> Users.Users -> [PrivilegeCondition]
8282
-> ServerEnv
8383
-> ServerPartE UserId
8484
guardAuthorised realm users privconds env = do
85-
(uid, _) <- guardAuthenticated realm users env
85+
uid <- guardAuthenticated realm users env
8686
guardPriviledged users uid privconds
8787
return uid
8888

@@ -96,14 +96,14 @@ guardAuthorised realm users privconds env = do
9696
-- It only checks the user is known, it does not imply that the user is
9797
-- authorised to do anything in particular, see 'guardAuthorised'.
9898
--
99-
guardAuthenticated :: RealmName -> Users.Users -> ServerEnv -> ServerPartE (UserId, UserInfo)
99+
guardAuthenticated :: RealmName -> Users.Users -> ServerEnv -> ServerPartE UserId
100100
guardAuthenticated realm users env = do
101101
authres <- checkAuthenticated realm users env
102102
case authres of
103103
Left autherr -> throwError =<< authErrorResponse realm autherr
104104
Right info -> return info
105105

106-
checkAuthenticated :: ServerMonad m => RealmName -> Users.Users -> ServerEnv -> m (Either AuthError (UserId, UserInfo))
106+
checkAuthenticated :: ServerMonad m => RealmName -> Users.Users -> ServerEnv -> m (Either AuthError UserId)
107107
checkAuthenticated realm users ServerEnv { serverRequiredBaseHostHeader } = do
108108
mbHost <- getHost
109109
case mbHost of
@@ -251,15 +251,15 @@ plainHttp req
251251

252252
-- | Handle a auth request using an access token
253253
checkTokenAuth :: Users.Users -> BS.ByteString
254-
-> Either AuthError (UserId, UserInfo)
254+
-> Either AuthError UserId
255255
checkTokenAuth users ahdr = do
256256
parsedToken <-
257257
case Users.parseOriginalToken (T.decodeUtf8 ahdr) of
258258
Left _ -> Left BadApiKeyError
259259
Right tok -> Right (Users.convertToken tok)
260260
(uid, uinfo) <- Users.lookupAuthToken parsedToken users ?! BadApiKeyError
261261
_ <- getUserAuth uinfo ?! UserStatusError uid uinfo
262-
return (uid, uinfo)
262+
return uid
263263

264264
------------------------------------------------------------------------
265265
-- Basic auth method
@@ -268,15 +268,15 @@ checkTokenAuth users ahdr = do
268268
-- | Use HTTP Basic auth to authenticate the client as an active enabled user.
269269
--
270270
checkBasicAuth :: Users.Users -> RealmName -> BS.ByteString
271-
-> Either AuthError (UserId, UserInfo)
271+
-> Either AuthError UserId
272272
checkBasicAuth users realm ahdr = do
273273
authInfo <- getBasicAuthInfo realm ahdr ?! UnrecognizedAuthError
274274
let uname = basicUsername authInfo
275275
(uid, uinfo) <- Users.lookupUserName uname users ?! NoSuchUserError uname
276276
uauth <- getUserAuth uinfo ?! UserStatusError uid uinfo
277277
let passwdhash = getPasswdHash uauth
278278
guard (checkBasicAuthInfo passwdhash authInfo) ?! PasswordMismatchError uid uinfo
279-
return (uid, uinfo)
279+
return uid
280280

281281
getBasicAuthInfo :: RealmName -> BS.ByteString -> Maybe BasicAuthInfo
282282
getBasicAuthInfo realm authHeader
@@ -327,7 +327,7 @@ headerBasicAuthChallenge (RealmName realmName) =
327327
-- | Use HTTP Digest auth to authenticate the client as an active enabled user.
328328
--
329329
checkDigestAuth :: Users.Users -> BS.ByteString -> Request
330-
-> Either AuthError (UserId, UserInfo)
330+
-> Either AuthError UserId
331331
checkDigestAuth users ahdr req = do
332332
authInfo <- getDigestAuthInfo ahdr req ?! UnrecognizedAuthError
333333
let uname = digestUsername authInfo
@@ -337,7 +337,7 @@ checkDigestAuth users ahdr req = do
337337
guard (checkDigestAuthInfo passwdhash authInfo) ?! PasswordMismatchError uid uinfo
338338
-- TODO: if we want to prevent replay attacks, then we must check the
339339
-- nonce and nonce count and issue stale=true replies.
340-
return (uid, uinfo)
340+
return uid
341341

342342
-- | retrieve the Digest auth info from the headers
343343
--

0 commit comments

Comments
 (0)