Skip to content

302 redirect on Challenge handler - 401 expected #19

Description

During an upgrade of net6.0 -> net.8.0 and v3.x of the NEasyAuthMiddleware has proven somewhat problematic.

We have existing automated tests (xunit) that check for scenarios involving unauthenticated clients with expectations and assertions of a 401 return from our controllers. The default behaviour of v2.*.

Changes made under #15, initiated by issue #11 now mean that auth middleware returns a redirect 302 when we verify.

Adopting a workaround similar to that under #11 resolves this issue for the moment but would it be possible for EasyAuthOptions to be extended with a "NoRedirectOnChallenge" property?

builder.Services.AddEasyAuth(
    o =>
    {
        o.ForwardChallenge = o.ForwardSignOut = "MyEasyAuth";
    })
    .AddScheme<EasyAuthOptions, EasyAuthSignOutAuthenticationHandler>("MyEasyAuth", _ => { });
internal class EasyAuthNoChallengeAuthenticationHandler : AuthenticationHandler<EasyAuthOptions>
{
    public EasyAuthNoChallengeAuthenticationHandler(
        IOptionsMonitor<EasyAuthOptions> options,
        ILoggerFactory logger,
        UrlEncoder encoder) : base(options, logger, encoder) { }

    protected override Task<AuthenticateResult> HandleAuthenticateAsync() => throw new NotImplementedException();
}

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions