Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return 401 when basic auth credentials are invalid instead of failing with Internal Server Error (DEV-4585) #3514

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ final case class BaseEndpoints(authenticator: Authenticator)(implicit val r: zio
private def authenticateBasic(basic: UsernamePassword): Future[Either[RequestRejectedException, User]] =
UnsafeZioRun.runToFuture(
(for {
email <- ZIO.fromEither(Email.from(basic.username))
password <- ZIO.fromOption(basic.password)
user <- authenticator.authenticate(email, password)
} yield user._1).orElseFail(BadCredentialsException("Invalid credentials.")).asRight,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.asRight failed, need to use .either.

email <- ZIO
.fromEither(Email.from(basic.username))
.orElseFail(BadCredentialsException("Invalid credentials, email address expected."))
password <- ZIO
.fromOption(basic.password)
.orElseFail(BadCredentialsException("Invalid credentials, missing password."))
userAndJwt <- authenticator
.authenticate(email, password)
.orElseFail(BadCredentialsException("Invalid credentials."))
(user, _) = userAndJwt
} yield user).either,
)
}

Expand Down