Skip to content

How can I stop a request in the PreAuthenticationMiddleware? #942

Closed

Description

@ildoc

I have to do some checks on the request's jwt before ocelot authentication, so I'm doing them within the PreAuthenticationMiddleware like this:

var config = new OcelotPipelineConfiguration
{
    PreAuthenticationMiddleware = async (ctx, next) =>
    {
        var jwt = ctx.HttpContext.Request.Headers["Authorization"];

        if (jwtIsOk(jwt)) next.Invoke();
        // else ...
    }
};

app.UseOcelot(config).Wait();

Instead of not-invoking next, is it possible to return a custom response?
I'd like to return a 401 error

Activity

  1. locked and limited conversation to collaborators on Jan 27, 2024
  2. converted this issue into a discussion #1945 on Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions