Can't get security handler to return a 401 without a "challenge" attributes
See original GitHub issueContext:
Looking to return 401
s when a token is missing from a header. Front end redirects to login if this is the case
Issue:
The docs indicate that you can use cb(null, false)
from all securityHandlers to return a 401
. I only have one but I’m getting a 500
with:
No security handlers returned an acceptable response: token
Notes:
Looking at the code, it seems that without lastError.status
defined there’s no way to return a 401
Also, when running cb(null, false)
it seems the lastError
becomes the first argument. So with null
it would jump if (lastError)
and it the default cb
block
I’d be down to put in a PR, but I’m curious about you’d like the code to behave
Love your library! 💕
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (11 by maintainers)
Top Results From Across the Web
SpringBoot 401 UnAuthorized even with out security
RELEASE), the easiest way to get rid of the security issues is to add "WebSecurityConfig.java" to your project as follows:
Read more >HTTP 401 Unauthorized Error | What Is and How to Fix?
A network 401 Error signifies that the resource is barred and needs authentication that the client did not provide. Just like many HTTP...
Read more >How to Quickly Fix the 401 Unauthorized Error (5 Methods)
The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the ...
Read more >How to Fix a 401 Unauthorized Error? - GeeksforGeeks
It may be represented as 401 Unauthorized, Authorization required, HTTP error 401- Unauthorized. It represents that the request could not be ...
Read more >Overview of ASP.NET Core Authentication - Microsoft Learn
Authentication handler · Construct AuthenticationTicket objects representing the user's identity if authentication is successful. · Return 'no ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
so, if I understand correctly, the general business logic is:
401
I like that because if you want a specific response you can throw and then write a custom error handler
then the decision when implementing a handler would be:
return true
return false
throw new Error()
So the information presented here: https://github.com/kogosoftwarellc/open-api/tree/master/packages/openapi-security-handler is mainly for internal use by the library ? If we use express-openapi, the only difference is that we must define handlers with the return true/false/“throw” behavior instead of the callbacks?
I think that is what drove me on the wrong track, I thought that now I was supposed to instantiate a
const handler = new OpenAPISecurityHandler({...});
and use that somewhere, but I couldn’t figure out where.Thanks for that quick reply! Raphael