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

Error handling with multiple security schemes is inconsitant #870

Open
atalatable opened this issue Aug 20, 2024 · 0 comments
Open

Error handling with multiple security schemes is inconsitant #870

atalatable opened this issue Aug 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@atalatable
Copy link

Hello,

I use two different security scheme with an enum :

#[derive(SecurityScheme, Clone)]
#[oai(ty = "api_key", key_name = "KEY", key_in = "header", checker = "api_key_checker")]
struct Scheme1(pub Claims);

#[derive(SecurityScheme, Clone)]
#[oai(ty = "bearer", checker = "token_checker")]
struct Scheme2(pub Claims);

/// Unified Security Scheme
#[derive(SecurityScheme, Clone)]
enum Authentification {
    Scheme1(Scheme1),
    Scheme2(Scheme2),
}

Both checker function can return poem errors.

Expected Behavior

If I return an error from a scheme and the other key is not given, I should see the error from the first one.

In my example, if I give an invalid header KEY, and I don't give bearer, I should see the poem error coming from the checker function of the api KEY.

Actual Behavior

If the first scheme of the enum fails and the second is not given, the error returned is the error from the not given security scheme.

In my example, if I give an invalid header KEY, and I don't give bearer, I will never see error from the api key checker but I will see an error as if I didn't give a bearer.

Steps to Reproduce the Problem

I made a small server replicating the issue in this gist : https://gist.github.com/atalatable/0a6a9b65ba5ccd003e4c860ecfecdb82

To replicate, put a random API Key, and no Bearer. Here you get a "authorization error" and not a "custom error". Whereas if you set a Bearer and no API Key, you get a "Custom error".

Specifications

  • Version: poem 3.0.4 / poem-openapi 5.0.3
  • Platform:
  • Subsystem:

Maybe I understood wrong and this is not a bug if so, can anyone give me clarification please ? :)

@atalatable atalatable added the bug Something isn't working label Aug 20, 2024
@atalatable atalatable changed the title Error handling with multiple security schemes Error handling with multiple security schemes is inconsitant Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant