jhthorsen / mojolicious-plugin-openapi

OpenAPI / Swagger plugin for Mojolicious
53 stars 41 forks source link

Security - Several alternative methods #231

Closed amalonso closed 2 years ago

amalonso commented 2 years ago

Hi, I'm trying to configure two alternative authentication systems, but regardless of how I configure them, it always validates both.

I mean that to evaluate them with OR, they must be declared like this: security: [ {token: []}, {api_key: []}] And to be evaluated with AND, they must be declared this way: security: [ {token: [], api_key: []}]

Is there any issue in the code? Is there another way to get the OR condition? Thanks in advance

amalonso commented 2 years ago

Hi again. Sorry but it was an error on my code. On the plugin invocation I call return on every authentication callback so it fails when anyone fail.

plugin OpenAPI => {
    url => 'file://openapi/spec.yml'),
    security => {
        apiKey => sub {
            my ($c, $definition, $scopes, $cb) = @_;
            ...
            return ValidateApiKey($c, $definition->{name}, $cb);
        },
       token => sub {
            my ($c, $definition, $scopes, $cb) = @_;
            ...
            return ValidateToken($c, $definition->{name}, $cb);
        }
}