You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't pass security validation when using oapi validation middleware #221
Not sure this helps.. but you define auth globally in components, and you are applying it to the endpoint. You don't need to apply it to the endpoint since you are defining it globally as well. Try removing the security from the /admins endpoint.
As fas as I understand from this documentation, global or per-operation(per-method) security, both require "securitySchemes" on components to define security schemes.
If we want to globaly security we put "security: " tag at same level as paths/component, for example:
If I don't pass a validator function, I get the Security requirements failed error
Reacted by Leonard Seffer, Ernest Lebedev, Paul A, Ilya Hrankoŭski, kia keshmiri, davidsteed1, EmmieLin, Karine Ayrapetyants, Hiroki Uchiumi, Jordi Íñigo Griera and 3 more
In my case, I can't use global security, there are some my end-points that didn't requires authorization(jwt token), something like user registration etc, because of that, I solve my problem by creating custom oapi validation middleware based on current oapi validation middleware but I remove security validation part, and keeping the input validation part.
And then I create another custom middleware, based on echo jwtAuth middleware for token validation + user info extraction. and finally put that middleware to intercept request to oapi path that require authorization, so I do security validation and user info extraction from that jwt token in one step.
This code has changed quite a bit since this bug was filed, and I think you can achieve everything you want. As described above, a Skipper can be used to omit the validation in some API's, but you can also create a global security schema which requires JWT's and then on a per-operation basis, you can remove the security requirement by setting the security to nil, eg security: null
Activity
kevinduffey commentedon Aug 22, 2020
Not sure this helps.. but you define auth globally in components, and you are applying it to the endpoint. You don't need to apply it to the endpoint since you are defining it globally as well. Try removing the security from the /admins endpoint.
bandirsen commentedon Aug 22, 2020
@kevinduffey
As fas as I understand from this documentation, global or per-operation(per-method) security, both require "securitySchemes" on components to define security schemes.
If we want to globaly security we put "security: " tag at same level as paths/component, for example:
if we want per-operation (per-method) security we put 'security:' under method name like I do
kevinduffey commentedon Aug 22, 2020
That sounds right.. but your first example you had it on the method.. though that should be valid too.
zaccari commentedon Aug 26, 2020
I'm seeing this error as well, with the global
securityset (not at the path level):Removing the global
securitylets the validation pass:I'm looking into the issue now, just wanted to make a note of it here for reference
zaccari commentedon Aug 26, 2020
@bandirsen I was able to resolve the issue by providing a custom validator function to the options, like so:
If I don't pass a validator function, I get the
Security requirements failederrorbandirsen commentedon Aug 26, 2020
@zaccari
In my case, I can't use global security, there are some my end-points that didn't requires authorization(jwt token), something like user registration etc, because of that, I solve my problem by creating custom oapi validation middleware based on current oapi validation middleware but I remove security validation part, and keeping the input validation part.
And then I create another custom middleware, based on echo jwtAuth middleware for token validation + user info extraction. and finally put that middleware to intercept request to oapi path that require authorization, so I do security validation and user info extraction from that jwt token in one step.
silenzium commentedon Apr 5, 2023
@bandirsen
You can exclude your custom routes with the Skipper like this:
This will skip validation for routes that don't start with
/api/.mromaszewicz commentedon Feb 7, 2026
This code has changed quite a bit since this bug was filed, and I think you can achieve everything you want. As described above, a Skipper can be used to omit the validation in some API's, but you can also create a global security schema which requires JWT's and then on a per-operation basis, you can remove the security requirement by setting the security to nil, eg
security: null