rack-jwt
rack-jwt copied to clipboard
Exclude auth for root path only
Hey @eparreno 👋
Merging this PR will allow a dev to exclude the root path ('/'
) without excluding all paths starting with a /
from the JWT token auth check.
This comes handy when we want to have a pretty landing/docs page mounted on /
and an JWT auth API that serves from other paths, i.e. /users
.
I like and need this exact case.
Anything I can do to push this forward and help getting this merged?
For example, I could make it more generic using a regex instead of start_with()
? e.g. |ex| env['PATH_INFO'].match?(ex)
that would probably degrade performance and not be backwards compatible, but does give implementers more freedom.
Alternatively, a switch based on wether it is a string, or a regex:
@exclude.any? { |ex|
path = env['PATH_INFO']
ex.is_a?(String) && path.start_with?(ex) || ex.is_a?(Regexp) && path.match?(ex)
}
But then a tad more readable :)
Anything we can do to help get this merged?