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

Make Endpoint respond with a 401 status code if the Authorization header is missing #3281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

notxcain
Copy link

/claim #3235

@@ -340,9 +340,10 @@ final case class Endpoint[PathInput, Input, Err, Output, Auth <: AuthType](
case Some(HttpCodecError.CustomError("SchemaTransformationFailure", message))
if maybeUnauthedResponse.isDefined && message.endsWith(" auth required") =>
maybeUnauthedResponse.get
case Some(_) =>
case Some(HttpCodecError.MissingAuthorizationHeader) =>
Handler.succeed(Response.unauthorized)
Copy link
Author

Choose a reason for hiding this comment

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

Let me know if this should be reported the same way is any other missing header.

case Some(_) =>
case Some(HttpCodecError.MissingAuthorizationHeader) =>
Handler.succeed(Response.unauthorized)
case Some(error) =>
Copy link
Author

Choose a reason for hiding this comment

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

Not sure why it was not written this way, as it looks like in this case asHttpCodecError provides the same value as cause.defects.head.asInstanceOf[HttpCodecError].

@@ -33,6 +33,9 @@ object HttpCodecError {
final case class MissingHeader(headerName: String) extends HttpCodecError {
def message = s"Missing header $headerName"
}
final case object MissingAuthorizationHeader extends HttpCodecError {
Copy link
Author

@notxcain notxcain Jan 22, 2025

Choose a reason for hiding this comment

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

I believe introducing a special case for that purpose helps with reasoning. Let me know if you'd like this to be implement using MissingHeader.

@notxcain notxcain marked this pull request as ready for review January 22, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant