|
3 | 3 | -- We authenticate clients using HTTP Basic or Digest authentication and we
|
4 | 4 | -- authorise users based on membership of particular user groups.
|
5 | 5 | --
|
6 |
| -{-# LANGUAGE PatternGuards #-} |
| 6 | +{-# LANGUAGE LambdaCase, PatternGuards #-} |
7 | 7 | module Distribution.Server.Framework.Auth (
|
8 | 8 | -- * Checking authorisation
|
9 | 9 | guardAuthorised,
|
@@ -428,26 +428,29 @@ data AuthError = NoAuthError
|
428 | 428 |
|
429 | 429 | authErrorResponse :: MonadIO m => RealmName -> AuthError -> m ErrorResponse
|
430 | 430 | authErrorResponse realm autherr = do
|
431 |
| - digestHeader <- liftIO (headerDigestAuthChallenge realm) |
432 |
| - return $! (toErrorResponse autherr) { errorHeaders = [digestHeader] } |
433 |
| - where |
434 |
| - toErrorResponse :: AuthError -> ErrorResponse |
435 |
| - toErrorResponse NoAuthError = |
436 |
| - ErrorResponse 401 [] "No authorization provided" [] |
437 |
| - |
438 |
| - toErrorResponse UnrecognizedAuthError = |
439 |
| - ErrorResponse 400 [] "Authorization scheme not recognized" [] |
440 |
| - |
441 |
| - toErrorResponse InsecureAuthError = |
442 |
| - ErrorResponse 400 [] "Authorization scheme not allowed over plain http" |
443 |
| - [ MText $ "HTTP Basic and X-ApiKey authorization methods leak " |
444 |
| - ++ "information when used over plain HTTP. Either use HTTPS " |
445 |
| - ++ "or if you must use plain HTTP for authorised requests then " |
446 |
| - ++ "use HTTP Digest authentication." ] |
447 |
| - |
448 |
| - toErrorResponse BadApiKeyError = |
449 |
| - ErrorResponse 401 [] "Bad auth token" [] |
450 |
| - |
451 |
| - -- we don't want to leak info for the other cases, so same message for them all: |
452 |
| - toErrorResponse _ = |
453 |
| - ErrorResponse 401 [] "Username or password incorrect" [] |
| 431 | + digestHeader <- liftIO (headerDigestAuthChallenge realm) |
| 432 | + |
| 433 | + let |
| 434 | + toErrorResponse :: AuthError -> ErrorResponse |
| 435 | + toErrorResponse = \case |
| 436 | + NoAuthError -> |
| 437 | + ErrorResponse 401 [digestHeader] "No authorization provided" [] |
| 438 | + |
| 439 | + UnrecognizedAuthError -> |
| 440 | + ErrorResponse 400 [digestHeader] "Authorization scheme not recognized" [] |
| 441 | + |
| 442 | + InsecureAuthError -> |
| 443 | + ErrorResponse 400 [digestHeader] "Authorization scheme not allowed over plain http" |
| 444 | + [ MText $ "HTTP Basic and X-ApiKey authorization methods leak " |
| 445 | + ++ "information when used over plain HTTP. Either use HTTPS " |
| 446 | + ++ "or if you must use plain HTTP for authorised requests then " |
| 447 | + ++ "use HTTP Digest authentication." ] |
| 448 | + |
| 449 | + BadApiKeyError -> |
| 450 | + ErrorResponse 401 [digestHeader] "Bad auth token" [] |
| 451 | + |
| 452 | + -- we don't want to leak info for the other cases, so same message for them all: |
| 453 | + _ -> |
| 454 | + ErrorResponse 401 [digestHeader] "Username or password incorrect" [] |
| 455 | + |
| 456 | + return $! toErrorResponse autherr |
0 commit comments